jackz
March 30, 2024, 2:27pm
1
Godot Version
4.2.1
Question
I have a scene with a script and want to use another scene (with script). The other scene is not linked to my current scene.
I tried it with:
@export var testScene: PackedScene
But when I use a scene in this export, I cannot use any varialbes of that scene. For example this is not working:
print(testScene.myVariable)
Is there a way to do this?
1 Like
EX74
March 30, 2024, 2:35pm
2
var my_scene = testScene.instantiate()
print( my_scene.myVariable )
1 Like
jackz
March 30, 2024, 2:41pm
3
Okay, thx. Almost there. But @onready variables are null. So if the testScene contains for example:
@onready var status: Node = $Status
that status will be null on calling. Any idea?
1 Like
EX74
March 30, 2024, 10:28pm
4
try
var my_scene = testScene.instantiate()
var status = my_scene.get_node("Status")
print( status )
1 Like
It’s because on ready is done when the scene is added to the scene_tree, not just instantiated. You should add your test scene to the tree if you want to use it this way.
1 Like
system
Closed
April 29, 2024, 11:36pm
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.