Condition "parent->has_node(name)" is true. Returning: ERR_INVALID_DATA

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

Error: E 0:00:06:0225 on_spawn_receive: Condition “parent->has_node(name)” is true. Returning: ERR_INVALID_DATA
This happens on the client for the amount of players-1 (this could be minus the host or minus themself)
I have looked around Bing AI’s Copilot with Chat GPT-4, Open AI’s Chat GPT-3.5, stack overflow, godot forums, and google.

It might be complaining about what you passed to the has_node() method. It needs a NodePath.

No, I dont think I provided enough context for this question (the idea was to use the github link), but I did find a solution, the problem was line 6

func add_player(id = 1):
	var player = player_scene.instantiate()
	player.position.y += 5
	player.position.x += 2
	player.name = str(id)
	add_child(player, true)
	print("Added player with ID", id)

the sollution was to add

if not multiplayer.is_server():
	return

and after adding basic error checking I left with:

func add_player(id = 1):
	if not multiplayer.is_server():
		return
	if has_node(str(id)):
		print("A player with ID", id, "already exists.")
		return
	var player = player_scene.instantiate()
	player.position.y += 5
	player.position.x += 2
	player.name = str(id)  # Use the unique network ID
	add_child(player, true)
	print("Added player with ID", id)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.