I don't see added Object in Scene (C# Godot4)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By insaneNic

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.

:bust_in_silhouette: Reply From: Hralok

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)

:bust_in_silhouette: Reply From: Hralok

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?

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?

insaneNic | 2023-07-09 07:32

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

Hralok | 2023-07-09 07:54