-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Labels
Description
hi, i use godot 4 beta 8 and want to know the usage of MultiplayerSpawner ?
var gltf := GLTFDocument.new()
var gltf_state := GLTFState.new()
var path = "C:/Users/SuperUserName/Documents/godot-workspace/godot-data/Fox.glb"
if FileAccess.file_exists(path):
print("File to spawn exists")
else:
print("File to spawn does not exist")
return
var snd_file = FileAccess.open(path, FileAccess.READ)
var fileBytes = PackedByteArray()
fileBytes = snd_file.get_buffer(snd_file.get_length())
gltf.append_from_buffer(fileBytes, "base_path?", gltf_state)
var node = gltf.generate_scene(gltf_state)
# save gltf as a scene with res:// path, to later add the scene to MultiplayerSpawner.add_spawnable_scene ??
var scene = PackedScene.new()
var result = scene.pack(node)
if result == OK:
var error = ResourceSaver.save(scene, "res://myscene.scn") # Or "user://..."
if error != OK:
print("An error occurred while saving the scene to disk.")
var mpspawner := MultiplayerSpawner.new()
mpspawner.add_spawnable_scene("C:/Users/SuperUserName/Documents/godot-workspace/Godot-4-Networking-Demonstration-Complete-main/myscene.scn")
# mpspawner.add_spawnable_scene("res://myscene.scn")
print("spawnable scene count after adding myscene.scn:" + str(mpspawner.get_spawnable_scene_count()) )
mpspawner.spawn()
void add_spawnable_scene ( [String](https://docs.godotengine.org/en/latest/classes/class_string.html#class-string) path )
Adds a scene path to spawnable scenes, making it automatically replicated from the multiplayer authority to other peers when added as children of the node pointed by [spawn_path](https://docs.godotengine.org/en/latest/classes/class_multiplayerspawner.html#class-multiplayerspawner-property-spawn-path).
Does the spawner sends the myscene.scn to the peers and "add_child" it there ? If so , how do i do that ?
I also want to use the MultiplayerSynchronizer later to update e.g. the position of the imported scenes.?