The difference between Instant and New
Asked Answered
D

3

0

CardScene.Instantiate() as Card;
and
new Card()
What is the difference between them?
Why do I encounter the error of node not being found when using 'newCard()'
Does anyone know? Please answer me, thank you

Downandout answered 20/2 at 11:59 Comment(0)
M
1

https://docs.godotengine.org/en/stable/classes/class_packedscene.html#class-packedscene-method-instantiate
https://docs.godotengine.org/en/stable/classes/class_gdscript.html#class-gdscript-method-new

This would imply you're searching the SceneTree for the instanced node - you must add it to the tree for it to exist in the tree, e.g. by calling add_child on an existing node (where the engine will then call _ready).

Mealy answered 20/2 at 12:23 Comment(0)
D
0

Downandout More precisely, the 'new' method does not trigger the _Ready() method

Downandout answered 20/2 at 12:12 Comment(0)
M
1

https://docs.godotengine.org/en/stable/classes/class_packedscene.html#class-packedscene-method-instantiate
https://docs.godotengine.org/en/stable/classes/class_gdscript.html#class-gdscript-method-new

This would imply you're searching the SceneTree for the instanced node - you must add it to the tree for it to exist in the tree, e.g. by calling add_child on an existing node (where the engine will then call _ready).

Mealy answered 20/2 at 12:23 Comment(0)
D
0

Mealy thank you

Downandout answered 20/2 at 13:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.