Hey, I'm making a peer-to-peer battleship game and I use a ray query to get the position of the mouse on a plane (the "board"). To configure this ray query, I am calling the function configure_raycast.
When the first player creates the server and becomes a peer, this function works just fine. Then the second player joins and the function is called again, this time for the second player, obviously.
However, after the _ready function is finished and the _process function is called, the ray query is just not configured anymore for the second player. For the first player the ray query is still configured.
This is the relevant code from the player script:
var ray_query = PhysicsRayQueryParameters3D.new()
func _enter_tree():
var parent_name = str(get_parent().name)
set_multiplayer_authority(parent_name.to_int())
# the script is not on the root of the player scene,
# hence the get_parent().name
func _ready():
if !is_multiplayer_authority():
return
configure_raycast.rpc_id(multiplayer.get_unique_id())
@rpc("call_local")
func configure_raycast(collision_mask_ray_query: int = 2):
ray_query.collision_mask = collision_mask_ray_query
ray_query.collide_with_areas = true
ray_query.collide_with_bodies = false
I'm not sure if I used the @rpc correctly here, but I tried without and that has the exact same result.
This also happens with any variable assigning I do in _ready, but anything that has an @onready tag, or is a field variable in general, works as expected.
For example this works:
var ray_query = PhysicsRayQueryParameters3D.new()
And this does not:
var ray_query
func _ready():
ray_query = PhysicsRayQueryParameters3D.new()
Is there something wrong with my multiplayer setup if this is happening, or how do I solve this?
If you need any more code, or there are any questions, I will happily clarify. Thanks for any help.