Fix cloned external connections

This commit is contained in:
Pascal Serrarens 2026-04-28 17:18:31 +02:00
parent b2bc92b05f
commit ffcf420715
3 changed files with 19 additions and 18 deletions

View File

@ -70,14 +70,7 @@ namespace NanoBrain {
get => base.currentNucleus; get => base.currentNucleus;
set { set {
base.currentNucleus = value; base.currentNucleus = value;
this.currentPrefabNucleus = this.prefab.GetNucleus(value.name); this.currentPrefabNucleus = this.prefab.GetNucleus(value.name);
// int nucleusIx = this.prefab.nuclei.IndexOf(base.currentNucleus);
// if (nucleusIx >= 0)
// this.currentPrefabNucleus = this.prefab.nuclei[nucleusIx];
// else {
// Debug.LogWarning("Could not find nucleus in prefab");
// this.currentPrefabNucleus = this.prefab.GetNucleus(value.name);
// }
} }
} }
@ -150,7 +143,6 @@ namespace NanoBrain {
if (serializedObject == null || serializedObject.targetObject == null) if (serializedObject == null || serializedObject.targetObject == null)
return; return;
serializedObject.Update(); serializedObject.Update();
GUIStyle boldTextFieldStyle = new(EditorStyles.textField) { GUIStyle boldTextFieldStyle = new(EditorStyles.textField) {
@ -171,7 +163,7 @@ namespace NanoBrain {
GUILayout.Label(nucleusType, headerStyle); GUILayout.Label(nucleusType, headerStyle);
// Nucleus name // Nucleus name
Cluster cluster = this.currentNucleus as Cluster; Cluster cluster = this.currentPrefabNucleus as Cluster;
if (cluster != null) { if (cluster != null) {
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
if (GUILayout.Button(this.currentNucleus.parent.name)) if (GUILayout.Button(this.currentNucleus.parent.name))
@ -212,7 +204,7 @@ namespace NanoBrain {
if (this.currentNucleus is MemoryCell memory) if (this.currentNucleus is MemoryCell memory)
MemoryCellInspector(memory, ref anythingChanged); MemoryCellInspector(memory, ref anythingChanged);
// Cluster // Cluster
else if (cluster != null) //(this.currentNucleus is Cluster cluster) else if (cluster != null)
ClusterInspector(cluster, ref anythingChanged); ClusterInspector(cluster, ref anythingChanged);
// Other // Other
else else
@ -266,7 +258,6 @@ namespace NanoBrain {
if (GUILayout.Button("Add")) { if (GUILayout.Button("Add")) {
Undo.RecordObject(prefabAsset, "Array add " + prefabAsset.name); Undo.RecordObject(prefabAsset, "Array add " + prefabAsset.name);
//cluster.AddInstance(this.prefab);
cluster.AddInstance(); cluster.AddInstance();
anythingChanged = true; anythingChanged = true;
} }

View File

@ -32,9 +32,11 @@ namespace NanoBrain {
} }
// This should not be serialized // This should not be serialized
[SerializeReference] //[SerializeReference]
[NonSerialized]
public Cluster[] siblingClusters; public Cluster[] siblingClusters;
// This serialization should be enough // This serialization should be enough
[SerializeField]
public int instanceCount = 1; public int instanceCount = 1;
public Dictionary<int, Cluster> thingClusters = new(); public Dictionary<int, Cluster> thingClusters = new();
@ -125,6 +127,7 @@ namespace NanoBrain {
continue; continue;
clonedSender.AddReceiver(clonedNeuron, prefabSynapse.weight); clonedSender.AddReceiver(clonedNeuron, prefabSynapse.weight);
//Debug.Log($"Add synapse {clonedCluster.name}.{clonedSender.name} -> {clonedNeuron.name} [{clonedSender.receivers.Count}]");
} }
else { else {
int ix = GetNucleusIndex(prefabNuclei, prefabSynapse.neuron); int ix = GetNucleusIndex(prefabNuclei, prefabSynapse.neuron);
@ -135,6 +138,7 @@ namespace NanoBrain {
// Copy the receivers which will also create the synapse // Copy the receivers which will also create the synapse
clonedSender.AddReceiver(clonedNeuron, prefabSynapse.weight); clonedSender.AddReceiver(clonedNeuron, prefabSynapse.weight);
// Debug.Log($"Add synapse {clonedSender.name} -> {clonedNeuron.name}");
} }
} }
@ -249,10 +253,10 @@ namespace NanoBrain {
} }
*/ */
foreach (Nucleus nucleus in this.clusterNuclei) { // foreach (Nucleus nucleus in this.clusterNuclei) {
if (nucleus is Cluster clonedSubCluster) // if (nucleus is Cluster clonedSubCluster)
RestoreAllExternalReceivers(clonedSubCluster, this.prefab, this); // RestoreAllExternalReceivers(clonedSubCluster, this.prefab, this);
} // }
} }
/// <summary> /// <summary>
@ -718,10 +722,14 @@ namespace NanoBrain {
if (outputNucleus is not Neuron output) if (outputNucleus is not Neuron output)
continue; continue;
// Debug.Log($"output {this.name} {outputNucleus.name}");
foreach (Nucleus receiver in output.receivers) { foreach (Nucleus receiver in output.receivers) {
// Debug.Log($"output {receiver.name}");
// Only add receivers outside this cluster // Only add receivers outside this cluster
if (receiver.clusterPrefab != this.prefab) if (receiver.clusterPrefab != this.prefab) {
// Debug.Log($" YES");
receivers.Add(receiver); receivers.Add(receiver);
}
} }
} }
return receivers; return receivers;

View File

@ -526,6 +526,8 @@ namespace NanoBrain {
public virtual void AddReceiver(Nucleus receiverToAdd, float weight = 1) { public virtual void AddReceiver(Nucleus receiverToAdd, float weight = 1) {
this._receivers.Add(receiverToAdd); this._receivers.Add(receiverToAdd);
receiverToAdd.AddSynapse(this, weight); receiverToAdd.AddSynapse(this, weight);
//Debug.Log($"Add synapse {this.clusterPrefab.name}.{this.name} -> {receiverToAdd.name} --- [{this.receivers.Count}]");
} }
public virtual void RemoveReceiver(Nucleus receiverToRemove) { public virtual void RemoveReceiver(Nucleus receiverToRemove) {