Create a node to Instance other nodes for speed and efficiency

Godot Version

Godot 4.5

Question

I am making a node to help with instancing my other nodes mainly my camera.
My Question is “Is this the right way, Otherwise what would be the right way, or Is there a better way to do this without making a headache for myself?” (Only really need an answer to one of these its hard to ask seemingly simple questions)

The whole reason I am doing this is to help with multiplayer and making the camera so I don’t have to Make each camera and UI separately. Instead I will just plop this into my scene perhaps assign a player and move on.

This is the node I am creating to instance my other nodes:

class_name PlayerMain

extends Node

const PlayerGUI = preload("res://Scenes/RigsAndTemplates/GUIAndViewport.tscn")

const PlayerCamera = preload("res://Scenes/RigsAndTemplates/PlayerCamera2d.tscn")

func Add_Packages():
	
	var SpawnGUI = PlayerGUI.instantiate()
	var SpawnCamera = PlayerCamera.instantiate()
	
	
	add_child(SpawnGUI)
	print(PlayerGUI.tranform)
	PlayerGUI.add_child(SpawnCamera)
	print(PlayerCamera.tranform)

I think this should work but it doesn’t and I get this error.

ERROR: Could not create child process: --version

OK to extrapolate on my problem.

This is my player scene and script (So far)

I am attempting to add this node to another node. (Without instancing it, explains why in a sec)

And I want it to have all its children, I was attempting to make it get its children as a work around but that seems to not be working. Is there a method to accomplish this without causing disruptions or experiencing errors? :melting_face:

Seems like you should be able to instantiate children in the editor. In mulitplayer you can hide non-authority UI and set each camera’s current based on the authority.

Do you get any other errors?

Yes, Nevermind my initial incorrect statement.*
[No, I don’t get any other errors. :melting_face:]*

My goal was just to have an all in one node that allowed me to just click a button add this node and pull the others with it. sort of an all in one player node I can add as I see fit. [If just instancing them does it anyway then I didn’t need to ask this question.] – IT DOSEN’T
Thank you for the assistance.

This is my scene (its simple)

Instead of using a script to instantiate you can click the link icon to the right of the plus, or drag-and-drop scene .tscn files from the FileSystem panel in the bottom left into the Scene panel in the top left.

The errors pertain to the Godot steam plugin you have semi-installed, some DLL files are missing that the extension expects, it may have been installed wrong.

1 Like