mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Fix destroying assets error
Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true); UnityEngine.Object:Destroy (UnityEngine.Object) XNode.NodeGraph:Clear () (at Assets/Scripts/xNode-1.8.0/Scripts/NodeGraph.cs:51) XNode.NodeGraph:OnDestroy () (at Assets/Scripts/xNode-1.8.0/Scripts/NodeGraph.cs:83) This can be caused by destroying instantiated NodeGraph. Fixed by instantiating nodes in Awake.
This commit is contained in:
parent
286b9a167a
commit
3623aa6d71
@ -11,6 +11,15 @@ namespace XNode {
|
||||
/// See: <see cref="AddNode{T}"/> </summary>
|
||||
[SerializeField] public List<Node> nodes = new List<Node>();
|
||||
|
||||
private void Awake() {
|
||||
List<Node> newNodes = new List<Node>(nodes.Count);
|
||||
foreach (var node in nodes) {
|
||||
newNodes.Add(Instantiate(node));
|
||||
}
|
||||
nodes.Clear();
|
||||
nodes = newNodes;
|
||||
}
|
||||
|
||||
/// <summary> Add a node to the graph by type (convenience method - will call the System.Type version) </summary>
|
||||
public T AddNode<T>() where T : Node {
|
||||
return AddNode(typeof(T)) as T;
|
||||
@ -47,6 +56,7 @@ namespace XNode {
|
||||
public virtual void Clear() {
|
||||
if (Application.isPlaying) {
|
||||
for (int i = 0; i < nodes.Count; i++) {
|
||||
if(nodes[i]) //Graph destroy nodes only here, but this check prevent nullref when node was destroyed outside
|
||||
Destroy(nodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user