#Copying entire scene tree to a variable
1 messages · Page 1 of 1 (latest)
Just
SceneTree tree_reference = some_node.GetTree()
The SceneTree is not the actual owner of the nodes, that would the Root of the tree.
But i don't really understand what is your goal here.
What did you mean with this exactly?
"Godot sets variable to node without children."
variable is set to node, yes, but Children property is empty
i have a scripting language in my game that needs to access nodes in current scene
There's only 2 reasons as to why it would have no children. Either the scene is empty at the time where you're checking (too early or during a scene change) OR the PackedScene loaded is simply empty.
fragment of code that assigns CurrentLevel to scene tree runs on _ready
reading the documentation it should work, because _ready runs when node and its children are ready
code that assigns is on topmost node
If it is running in an Autoload, those are ready before the scene even loads.
it's running in root node
public override void _Ready()
{
[...]
//initalize evil scripting language and run ready function
_scriptvm = new GodotVM() { CurrentLevel = GetTree() };
[...]
}```
GodotVM is
public class GodotVM : CeresVM
{
public SceneTree CurrentLevel { get; set; }
}```
CeresVM is virtual machine of scripting language i'm using
when I try to access CurrentLevel from class that inherits from Node, it works
when accessing the same variable from class that doesn't inherit Node it doesn't
found my solution