So say i have two scenes “Main” and “Second” both should contain player. Now i spawning player in scenes like
<code>func _load_player() -> void:
# Instantiate player and camera
var player = player_scene.instantiate()
var camera = camera_scene.instantiate()
# Add Nodes to tree
current_scene.add_child(player)
current_scene.add_child(camera)
# Set up player and camera
camera.player = player
player.camera_holder = camera
</code>
<code>func _load_player() -> void:
# Instantiate player and camera
var player = player_scene.instantiate()
var camera = camera_scene.instantiate()
# Add Nodes to tree
current_scene.add_child(player)
current_scene.add_child(camera)
# Set up player and camera
camera.player = player
player.camera_holder = camera
</code>
func _load_player() -> void:
# Instantiate player and camera
var player = player_scene.instantiate()
var camera = camera_scene.instantiate()
# Add Nodes to tree
current_scene.add_child(player)
current_scene.add_child(camera)
# Set up player and camera
camera.player = player
player.camera_holder = camera
where current_scene is scene to load in root node.
So question is. I can spawn player like these
<code>get_tree().root.add_child(player)
get_tree().root.add_child(camera)
</code>
<code>get_tree().root.add_child(player)
get_tree().root.add_child(camera)
</code>
get_tree().root.add_child(player)
get_tree().root.add_child(camera)
Which pros and cons i could get from that way?
My Pros is that i always know where is my player and camera say i can find it easily get_tree().root.get_node('Player')
New contributor
Jarvis Ronuken is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.