C# Godot Scene Instance - Ready/Enter Tree Functions Not called

dan369dan369 Posts: 4Member
edited October 18 in Programming


Apologies if this is a simple or stupid question but here i go.
I have a root empty "World" scene, that i want to add child nodes to, like below;

// World.cs file
// world _ready function
Level myLevel= new Level("res://maps/map1.tmx");
Node2D levelInstance = level.Instance();

& inside Level.cs

// Level.cs
// Note: Level inherits Node2D
public override void _EnterTree()

            GD.Print("entered tree - level");

        public override void _Ready()
            GD.Print("level ready");

I can see on screen and in the debugging remote that my scene is added to the tree and everything is fine.
However, inside my level class for my tiled map the enter_tree and _ready functions are never called?
Why is that?


  • dan369dan369 Posts: 4Member
    edited October 18

    Solved this, with the help from godot discoord :).
    In my world file, i dont need to instance the level, just add it in.

    Level mainHall = new Level("res://maps/map1.tmx", "mainHall");

    However, since the Level class contains the packedScene for the Tiled level, that needs to be added as a child for that to show;

    public Level(string path, string name) 
                Scene = ResourceLoader.Load<PackedScene>(path);
                Map = Scene.Instance() as Node2D; // Getter/Setter 
                this.Name = name;

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file