The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I have a Main node and a Scene called Block. I want to add multiple Blocks into the Main scene. Main does not have any Blocks as Children by default. The relevant code in Main.cs is:

public PackedScene BlockScene {get; set;}
for (int i = 0; i < 8; i++)
        Block block = BlockScene.Instantiate<Block>();
        Vector2 spawnPosition = new Vector2(
            x: (float)(12 + i*8),
            y: (float)(128)

in Block.cs I have

// Called when the node enters the scene tree for the first time.
public override void _Ready()
    var animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
    animatedSprite.Animation = "default";

public void Start(Vector2 pos){
    Position = pos;
    GetNode<CollisionShape2D>("CollisionShape2D").Disabled = false;

I know that the Blocks are added as Children to Main because I have printed all of the children of Main and they are there. I have also double checked that I have added the right scene to BlockScene. I have turned on Visible Collision Shapes and also don't see anything. I don't know what else I could possibly be missing. Thanks for your help.

Godot version v4.1.stable.mono.official [970459615]
in Engine by (19 points)

2 Answers

+1 vote
Best answer

I looked into your code and I think I figured out what the error is. After you instantiate your block, you running Start method, and after that you adding your block as a child to Main. When you adding node to scene tree by attaching it as a child to node that in scene tree already, than _Ready() method will called; so, you call your Start method on block, in this method you "Show();" block, after that you attach block as a child and Ready with "Hide();" will hide your block. Was my guess helpful?

by (75 points)
selected by

Thanks! I didn't know that Ready only gets called when you add them to the scene tree.

Also for the running tab tip. Do you know if Hidden objects are shown in the running tab?

Is node shown or hidden in running tree indicated exactly as in not running tree, by open or closed eye icon

0 votes

Hello man! Before I'll try to look into your code, do you know, that in the scene tree while the game is running a new tab is added at the top of the tree view there you can switch between the planned tree and the running one (it's called remote and local if I recall), so you can see running game tree with your own eyes in editor? If your answer is no, than I hope that it will be useful for you now and in future)

by (75 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.