From 7bcd4a6cf1d9b3c5844492e1ee45e440179195db Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 9 Feb 2026 09:22:31 +0100 Subject: [PATCH] ant and mouth share the same brain --- Cluster.cs | 8 ++++++-- Editor/ClusterInspector.cs | 2 +- Neuron.cs | 4 ++-- Nucleus.cs | 2 +- NucleusArray.cs | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Cluster.cs b/Cluster.cs index e9eeb18..e94417b 100644 --- a/Cluster.cs +++ b/Cluster.cs @@ -86,8 +86,12 @@ public class Cluster : Nucleus { int arrayIx = 0; foreach (Nucleus prefabArrayNucleus in prefabNucleus.array.nuclei) { int arrayNucleusIx = GetNucleusIndex(prefabNuclei, prefabArrayNucleus); + if (arrayNucleusIx >= 0) { Nucleus clonedArrayNucleus = clonedNuclei[arrayNucleusIx]; clonedArray.nuclei[arrayIx] = clonedArrayNucleus; + } else { + Debug.LogError($" Could not find prefab nuclues {prefabNucleus.name} in the clones"); + } arrayIx++; } clonedNucleus.array = clonedArray; @@ -138,9 +142,9 @@ public class Cluster : Nucleus { return sortedOrder; } - public override Nucleus Clone() { + public override Nucleus Clone(ClusterPrefab prefab) { //Neuron clone = new(this.cluster, this.name) { - Neuron clone = new(this.parent, this.name) { + Neuron clone = new(prefab, this.name) { array = this.array, }; diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index e1928f9..1fa78ee 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -550,7 +550,7 @@ public class ClusterInspector : Editor { EditorGUILayout.BeginHorizontal(); EditorGUILayout.IntField("Array size", neuroid.array.nuclei.Count()); if (GUILayout.Button("Add")) - neuroid.array.AddNucleus(); + neuroid.array.AddNucleus(this.cluster); if (GUILayout.Button("Del")) neuroid.array.RemoveNucleus(); EditorGUILayout.EndHorizontal(); diff --git a/Neuron.cs b/Neuron.cs index aa62c72..4b86845 100644 --- a/Neuron.cs +++ b/Neuron.cs @@ -139,8 +139,8 @@ public class Neuron : Nucleus { return clone; } - public override Nucleus Clone() { - Neuron clone = new(this.cluster, this.name) { + public override Nucleus Clone(ClusterPrefab prefab) { + Neuron clone = new(prefab, this.name) { //Neuron clone = new(this.parent, this.name) { array = this.array, curve = this.curve, diff --git a/Nucleus.cs b/Nucleus.cs index 247ffad..25bebb1 100644 --- a/Nucleus.cs +++ b/Nucleus.cs @@ -34,7 +34,7 @@ public abstract class Nucleus { public int stale = 1000; public abstract Nucleus ShallowCloneTo(Cluster parent); - public abstract Nucleus Clone(); + public abstract Nucleus Clone(ClusterPrefab prefab); #region Synapses diff --git a/NucleusArray.cs b/NucleusArray.cs index 543718d..368aac3 100644 --- a/NucleusArray.cs +++ b/NucleusArray.cs @@ -28,7 +28,7 @@ public class NucleusArray { } - public void AddNucleus() { + public void AddNucleus(ClusterPrefab prefab) { if (this._nuclei.Length == 0) { Debug.LogError("Empty perceptoid array, cannot add"); return; @@ -39,7 +39,7 @@ public class NucleusArray { for (int i = 0; i < this._nuclei.Length; i++) newArray[i] = this._nuclei[i]; if (this._nuclei[0] is Nucleus nucleus) - newArray[newLength - 1] = nucleus.Clone(); + newArray[newLength - 1] = nucleus.Clone(prefab); this._nuclei = newArray; }