Godot Version
4.5.1
Question
I am trying to spawn a bullet that is then spawned and synchronized between all players.
This works fine for the host, and clients can see the host’s bullets just fine. However, an error fires every time a bullet is fired on both host and clients, and bullets fired by clients are warped position 0,0,0 and then move through the ground extremely slowly.
Here is the code on the gun responsible for firing the bullet.
extends Node3D
var speed = 200
@onready var spawner: MultiplayerSpawner = $MultiplayerSpawner
@onready var spawn_location = get_tree().root.get_node("Main/GameWorld")
@export var projectile : PackedScene
func _ready() -> void:
spawner.spawn_path = spawn_location.get_path()
func fire():
var bullet = projectile.instantiate()
var camera = get_parent()
bullet.global_transform = camera.global_transform
bullet.speed = camera.global_transform.basis.z * speed
spawn_location.add_child(bullet, true)
The error it returns is
E 0:01:43:988 test_gun.gd:19 @ fire(): Condition "tobj.spawner != ObjectID()" is true. Returning: ERR_ALREADY_IN_USE
<C++ Source> modules/multiplayer/scene_replication_interface.cpp:164 @ on_spawn()
<Stack Trace> test_gun.gd:19 @ fire()
player.gd:60 @ _physics_process()
I… don’t really know what that means. Can anyone help me decipher this or tell me what I’m doing wrong?