Hi, How I can load a scene, that use a texture in a sprite, passing dynamically a texture as parameter? Thank you.
Load a scene with a parameter.
- Edited
There's a space between instancing a scene and adding the scene to the node hierarchy, where the scene is loaded but isn't active in the game; you can modify your scene anyway you want to in this period.
Thank you for your answer :) However it is not clear to me what you mean when you say "space between".
Can you give me an simple example in code please?
Thank you.
- Edited
@Vale-git said: Thank you for your answer :) However it is not clear to me what you mean when you say "space between".
Can you give me an simple example in code please?
Thank you.
func LoadAScene(with_a_parameter):
#scene loading logic
var inst = scene.instance() #instantiated, but not active in the hierarchy
# T H E S P A C E
inst.parameter = with_a_parameter
# B E T W E E N
add_child(inst) #active in the hierarchy, as a child of this node
@Somnivore said:
@Vale-git said: Thank you for your answer :) However it is not clear to me what you mean when you say "space between".
Can you give me an simple example in code please?
Thank you.
func LoadAScene(with_a_parameter): #scene loading logic var inst = scene.instance() #instantiated, but not active in the hierarchy # T H E S P A C E inst.parameter = with_a_parameter # B E T W E E N add_child(inst) #active in the hierarchy, as a child of this node
Ha.. that ones.. I wonder if exist something like this:
onready var _myScene= preload("res://myScene.tscn") myParameter
Or the same result is obtained with your example?
Thank you.
@Vale-git said:
@Somnivore said:
@Vale-git said: Thank you for your answer :) However it is not clear to me what you mean when you say "space between".
Can you give me an simple example in code please?
Thank you.
func LoadAScene(with_a_parameter): #scene loading logic var inst = scene.instance() #instantiated, but not active in the hierarchy # T H E S P A C E inst.parameter = with_a_parameter # B E T W E E N add_child(inst) #active in the hierarchy, as a child of this node
Ha.. that ones.. I wonder if exist something like this:
onready var _myScene= preload("res://myScene.tscn") myParameter
Or the same result is obtained with your example?
Thank you.
Preloading a scene doesn't instantiate it, it just cuts out the loading bit. It wouldn't make sense to do it that way, as it would imply all your instances from then forth will have myParameter
, and if that's the case you might as well just make that a part of the scene. To my knowledge there's no such functionality like that, and likely never will be.
Thank you for your clarification :)