Godot Version
godot-4
Question
I’ve noticed that when I add a scene with add_child() or add_sibling, I’ll add a scene with an attached script and the script does not run. I’ve found a workaround with set_script(), but this confuses me. If a scene includes a script along with all its children, shouldn’t adding the scene with code add everything, including the script?
Yes, it certainly should, and it definitely does, otherwise none of my component scenes would work.
Can you post example code of you adding a scene and the scene itself (admittedly this is going to be tough as it is about attached scripts, perhaps a screen shot would be better. I honestly don’t know TBH how you can share this so we can help further.)
Essentially I’m trying to make an infinite runner type game, so I repeatedly add “rooms” with code. Each room adds another room above it and then destroys itself later on. When I add a room like this
const ROOM = preload("res://room.tscn")
var new_room = ROOM.instantiate()
add_sibling(new_room)
The next room seems to have no script attached, as I can put debug text in the ready function and nothing displays.
try to
add_sibling.call_deferred(new_room)
its always thing to test run deferred
1 Like