-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Execute a C# Script from command line with C# Autoload results in two different SceneTree instances #62101
Comments
It's actually the same SceneTree instance, you can check that The reason why C# returns different instances when marshaling is that when autoloads execute their Since the SceneTree hasn't been initialized, when trying to get the managed type from the unmanaged type, we are unable to retrieve a tied managed instance from a CSharpInstance script instance. What this means is that we haven't created an instance of Instead, it retrieves the native instance binding which is just an instance of Later, the script instance is actually created so we can retrieve the tied managed instance and it results in a different instance in C#. So to resolve this issue we would could implement either of these two options:
I'm not sure which option is preferred. The autoloads are added to the scene in Lines 3058 to 3060 in a83eb16
The SceneTree is initialized by the OS after calling godot/platform/linuxbsd/godot_linuxbsd.cpp Lines 72 to 75 in a83eb16
godot/platform/linuxbsd/os_linuxbsd.cpp Line 900 in a83eb16
Either way this would require changes to Core, I don't think there's anything we can do in the .NET module to resolve this. |
To me, the autoloads are user code, so they shouldn't be added until everything is ready in the core. The ideal will be just after the |
This issue seems like it may be a duplicate of:
There are already some open PRs that fix those issues:
I haven't looked too deep but if you feel like those already cover this issue we can close as duplicate and you can track progress there. |
Thanks, I've subscribed to them, so, as soon as they were merged, I can test this specific issue and close it as solved. |
The mentioned PRs have been merged and are included in 4.2-dev.1. Can you check if the issue still exists? |
Tested in godot-4-2-dev-2, it worked like a charm. :) |
Godot version
3.4.3.stable.mono
System information
macOS Monterey 12.4
Issue description
Execute a Godot application using the
-s
parameter destroys previous SceneTree created before the script is executed. This can be noticed if the application has autoload nodes and they access toGetTree()
in the _Ready() method, which happens before the-s
script is created.It looks like Godot is creating a new SceneTree instance using the
-s
class which is totally different than the SceneTree instance returned from theGetTree()
method in the_Ready()
methods from any autoload object, instead of return the same instance. This is not happening after the_Initialize()
method, so, calling toGetTree()
in_Process()
method from any the autoload object return the right instance. But the previous wan has been disposed.Flow:
-s
script, which inherits fromSceneTree
GetTree()
method from autoloads_Ready()
returns a SceneTree. We will called it SceneTreeA
.B
is created using the-s
parameter.A
is disposed.GetTree()
call from autoloads returns theB
instance and any access to theA
instance will fail.Steps to reproduce
project.godot
:Minimal reproduction project
scene-tree-script-with-autoload-error.zip
The text was updated successfully, but these errors were encountered: