RPC work problems

I have function which send data in multiplayer to another player by rpc_id, but when I try to send data function do not send it.

func enemy_player_data(id,player:Player):
	print("Current_player:",id," ","Send player:",player.id)
	rpc_id(id,"transfer_deck",player)
@rpc
func transfer_deck(player:Player):
	GameManager.enemy = player
	print(GameManager.enemy)

What could be problem? Thanks for answer.

Do you call the rpc-method from the host? rpc’s can only be called by the host by default. if you want to change that you would have to put:

@rpc("any_peer")
func transfer_deck(player:Player):
...

I call it from client and server. Right now I do not have any dedicated server so I assign user as server. I already tried to use @rpc(“any_peer”), do not work for me :sleepy:

can you show the printed output on the console? Have you checked it the id’s are correct?

DB CLOSE, Clean closure: true
DB CLOSE, Clean closure: true
DB CLOSE, Clean closure: true
DB CLOSE, Clean closure: true
Wait for player!
Player connected298160685
Connected to server
Player connected1
DB CLOSE, Clean closure: true
DB CLOSE, Clean closure: true
Player to send:298160685 My id:1
Player to send:1 My id:298160685

I also checked by print(multiplayer.get_unique_id()) that “My id” is id who send data.

I found out problem. I removed my custom Player object from player

@rpc("any_peer")
func transfer_deck(player):

And now it provide such output:

DB CLOSE, Clean closure: true
DB CLOSE, Clean closure: true
DB CLOSE, Clean closure: true
DB CLOSE, Clean closure: true
Wait for player!
Connected to server
Player connected1
Player connected549206460
DB CLOSE, Clean closure: true
DB CLOSE, Clean closure: true
Player to send:1 My id:549206460
Player to send:549206460 My id:1
<EncodedObjectAsID#-9223371679365856040>
<EncodedObjectAsID#-9223371698676431656>

But still it need to be Player object not EncodedObjectAsID

1 Like
1 Like

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