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;
set {
base.currentNucleus = value;
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);
// }
this.currentPrefabNucleus = this.prefab.GetNucleus(value.name);
}
}
@ -150,7 +143,6 @@ namespace NanoBrain {
if (serializedObject == null || serializedObject.targetObject == null)
return;
serializedObject.Update();
GUIStyle boldTextFieldStyle = new(EditorStyles.textField) {
@ -171,7 +163,7 @@ namespace NanoBrain {
GUILayout.Label(nucleusType, headerStyle);
// Nucleus name
Cluster cluster = this.currentNucleus as Cluster;
Cluster cluster = this.currentPrefabNucleus as Cluster;
if (cluster != null) {
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button(this.currentNucleus.parent.name))
@ -212,7 +204,7 @@ namespace NanoBrain {
if (this.currentNucleus is MemoryCell memory)
MemoryCellInspector(memory, ref anythingChanged);
// Cluster
else if (cluster != null) //(this.currentNucleus is Cluster cluster)
else if (cluster != null)
ClusterInspector(cluster, ref anythingChanged);
// Other
else
@ -266,7 +258,6 @@ namespace NanoBrain {
if (GUILayout.Button("Add")) {
Undo.RecordObject(prefabAsset, "Array add " + prefabAsset.name);
//cluster.AddInstance(this.prefab);
cluster.AddInstance();
anythingChanged = true;
}

View File

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

View File

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