How to tell if a Node3D is disposed 'Cannot access a disposed object. Object name: 'Godot.Node3D'.'

Godot Version

4.2.1

Question

I add objects async and then call add child on the process thread. It looks like there are race conditions under which the item to add already got disposed. Is there a way to see if a Node3D is already disposed?

public ConcurrentQueue<Node3D> NodesToAdd { get; set; } = new ConcurrentQueue<Node3D>();
public override void _Process(double delta)
    {
        while (NodesToAdd.TryDequeue(out var node))
            AddChild(node);
    }

full info to help searches.
System.ObjectDisposedException
HResult=0x80131622
Message=Cannot access a disposed object.
Object name: ‘Godot.Node3D’.
Source=GodotSharp
StackTrace:
at Godot.GodotObject.GetPtr(GodotObject instance) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 75

public override void _Process(double delta)
    {
        while (NodesToAdd.TryDequeue(out var node))
            if(IsInstanceValid(node))
                AddChild(node);
    }

ok, that seems to work, I was looking for something on the object. We’ll see if I can get it to trigger again.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.