Characters return multiple values?


I’m having having an interesting problem where whenever I try to refer to a player (which is a CharacterBody2D) it returns multiple values. Here are the values a player is returning:


This is throwing a wrench in my plans, because checking the groups of a CharacterBody2D is fine (and my current intention), but the game crashes if you try to check the groups of an EncodedObjectAsID!

Here is the code on the player when they click the button to shoot:

func shoot():
	var new_projectile = projectile.instantiate()
	new_projectile.player = self
	get_parent().add_child(new_projectile, true)
	new_projectile.position = self.position
	if $Sprite2D.scale.x > 0:
		new_projectile.set_linear_velocity(Vector2(3000, 0))
		new_projectile.set_linear_velocity(Vector2(-3000, 0))

And here is the code of the bullet itself:

func _on_area_2d_area_entered(area):
	if area.is_in_group("hurt_box") and area.get_parent() != self.player:
		var direction = self.linear_velocity.x
		#var direction = facing
		var target = area.get_parent()
		get_parent().get_shot.rpc(target, direction)

Currently, all the function of the get_shot() function is just print(target), which gave the values I posted way above.

Why is this happening? How can I only get the value I expect when trying to reference a player (their CharacterBody2D node)?

Could you also sent the part of the code where it returns the values for player1


func get_shot(target, pDirection):

Try using instance_from_id

func get_shot(target_id, pDirection):
	var target = instance_from_id(target_id.object_id)

I always assumed rpc’s couldn’t be passed objects and used paths instead, if the above doesn’t work then try changing to paths like so

func get_shot(target_path: NodePath, pDirection):
	var target = get_node(target_path)

# call is different too :/
get_parent().get_shot.rpc(target.get_path(), direction)

This makes a lot of sense. It turns out that both the server and the client were trying to call the function, and the server was calling the node, where the clients are only passed the object IDs and not the nodes themselves. I set it to only have the server run the function and it started returning the correct values!