From 8801fa2ff2b96de74772e5e2bd5faab21502567f Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 21 Apr 2026 15:25:18 +0200 Subject: [PATCH] Cluster reimport fixes --- Editor/ClusterInspector.cs | 21 ++++++++++++++++++--- Runtime/Scripts/Core/Cluster.cs | 10 ++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index 30f7605..f32357e 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -439,9 +439,24 @@ namespace NanoBrain { } private void ReimportCluster(Cluster subCluster) { - Cluster reimportedCluster = new(subCluster.prefab, this.prefab); - subCluster.MoveReceivers(reimportedCluster); - // subcluster should be garbage now... + if (subCluster.siblingClusters == null || subCluster.siblingClusters.Length <= 0) { + Cluster reimportedCluster = new(subCluster.prefab, this.prefab); + subCluster.MoveReceivers(reimportedCluster); + // subcluster should be garbage now... + } + else { + List newSiblingsList = new(); + foreach (Cluster sibling in subCluster.siblingClusters) { + Cluster reimportedCluster = new(sibling.prefab, this.prefab) { + name = sibling.name + }; + sibling.MoveReceivers(reimportedCluster); + newSiblingsList.Add(reimportedCluster); + } + Cluster[] newSiblings = newSiblingsList.ToArray(); + foreach (Cluster sibling in newSiblings) + sibling.siblingClusters = newSiblings; + } } int selectedConnectNucleus = -1; diff --git a/Runtime/Scripts/Core/Cluster.cs b/Runtime/Scripts/Core/Cluster.cs index 4159793..d6ef274 100644 --- a/Runtime/Scripts/Core/Cluster.cs +++ b/Runtime/Scripts/Core/Cluster.cs @@ -402,6 +402,8 @@ namespace NanoBrain { } public bool SameSiblingsAs(Cluster[] otherSiblingClusters) { + if (this.siblingClusters == null) + return false; for (int ix = 0; ix < this.siblingClusters.Length; ix++) { if (this.siblingClusters[ix] != otherSiblingClusters[ix]) return false; @@ -592,23 +594,23 @@ namespace NanoBrain { } public void MoveReceivers(Cluster newCluster) { + Debug.Log($"Move receivers for {this.name} to {newCluster.name}"); foreach (Nucleus outputNucleus in this.clusterNuclei) { if (outputNucleus is not Neuron output) continue; // Find the existing output in the new cluster if (newCluster.GetNucleus(output.name) is not Neuron newOutput) { - Debug.LogWarning("Could not find output {output.name} in {newCluster.name}"); + Debug.LogWarning($"Could not find output {this.name}.{output.name} in {newCluster.name}"); continue; } - Debug.Log($"Check {output.name} receivers"); + Debug.Log($"Check {this.name}.{output.name} receivers"); Nucleus[] receivers = output.receivers.ToArray(); foreach (Nucleus receiver in receivers) { - Debug.Log("."); if (receiver.clusterPrefab != this.prefab) { // Replace synapse with new synapse // to the new cluster - Debug.Log($"move {receiver.name} from {output.name} to {newOutput.name}"); + Debug.Log($"move {receiver.name} from {this.name}.{output.name} to {newCluster.name}.{newOutput.name}"); Synapse synapse = receiver.GetSynapse(output); newOutput.AddReceiver(receiver, synapse.weight); output.RemoveReceiver(receiver);