Set start parameter to PackedScene.
-
I feel its an old problem of godot : https://github.com/godotengine/godot-proposals/issues/1513
I need to send information for a scene to indicate spawner locations , ammount , etc :
var p:PackedScene = load( "res://Scenes/scene.tscn" ) var scene = p.instantiate() scene.add_player( isMe , playerName , nodeId ) get_tree().change_scene_to_packed(p)
The func add_player is called, but when the scene loads it overwide any data in the scene and delete the information.
I saw everywhere, I mean, everybody using singletons to make this works, sorry, singleton is not a solution for me, is there a way to send information to the scene or this is just one more problem godot have and if I want to use it I need to use singletons ??? -
So I'm not sure what you are trying to do, so correct me out.
var p:PackedScene = load( "res://Scenes/scene.tscn" ) var scene = p.instantiate() scene.add_player( isMe , playerName , nodeId ) get_tree().change_scene_to_packed(p)
First you have a packed scene called
p
, instantiate it intoscene
variable. Then call aadd_player
function which suppose to store the parameter information.But then you have this
get_tree().change_scene_to_packed(p)
You are changing the
current scene
top
, which should be exactly what it says it is...
Whatever is inside this file:load( "res://Scenes/scene.tscn" )
Perhaps this is what you want?
var p:PackedScene = load( "res://Scenes/scene.tscn" ) var scene = p.instantiate() scene.add_player( isMe , playerName , nodeId ) var p2: PackedScene = PackedScene.new() p2.pack(scene) get_tree().change_scene_to_packed(p2)
-
@altria Thanks for replying, I am just trying to send some info to the new scene. Unfurtunally change_scene_to_packed also reset anything the scene have so it also dont work, I also cant see a diference of using pack or not... It may be a bug but I dont know.
Anyway, the only way I could find to send info to a new scene so far ( not using singletons ... ), was to completly change the way the engine works and use a top allways active root node ( same way other node engines works ... ). -
I am not sure I was clear, so, this is my point :
scene.add_player( isMe , playerName , nodeId ) ->>> this do nothing ... I need this to do something.
-
var p:PackedScene = load( "res://Scenes/scene.tscn" ) var scene = p.instantiate() scene.add_player( isMe , playerName , nodeId ) # <----- get_tree().change_scene_to_packed(p)
scene.add_player( isMe , playerName , nodeId )
This function call does nothing top
, it does something tovar scene
.get_tree().change_scene_to_packed(p)
But then you are trying to change the current scene, into
p
.
What I was trying to say is. Wrap that into a new PackedScene (p2), slap your scene there (that has all the informations/parameters/data), and
change_scene_to_packed
into that p2var p2: PackedScene = PackedScene.new() p2.pack(scene) get_tree().change_scene_to_packed(p2)
-
I tried that... Afther the change_scene_to_packed, every var set or object in the scene is deleted...
This is the code I tried:
scene.add_player( isMe , playerName , nodeId )
var pack: PackedScene = PackedScene.new()
pack.pack(scene)
get_tree().change_scene_to_packed( pack )in the new scene Node :
...
var playersToCreate: Array[String]
...
func add_player( activePlayer:bool , pName:String , pId:int
playersToCreate.append( str(int(activePlayer)) +","+ pName +","+ str(pId) )After the change_scene_to_packed, it executes again the var playersToCreate: Array[String] and resets the values, it may be a bug, but it prevents anyone to send any data to a new scene...
-
Just adding something I notice when debuging, its not the change_scene_to_packed itself that deletes the variables, its something that its executed after it runs in background, I guess its schedulle some startup procedure in another thread.
-
When you .pack() scene all the children that do not have that node as the owner not being saved, same with all variables that do not have export in front of them, maybe that's the issue?