#Getting an error in my multiplayer game when dealing with ServerRPCs

46 messages ยท Page 1 of 1 (latest)

pliant thorn
#

I made it such that when the player rolls it calls the server RPC to which it calls a ClientRPC to play the animation to all other clients (i am doing a host-client model). However, when rolling on clone, the other clone recieves the error "Only the owner can invoke a ServerRpc that requires ownership!". I can still continue playing the game as normal this error doesnt seem to have any effect. Ive looked online and the common suggestion was to mark the ServerRPC as anyone can call it however this then breaks the game not allowing the animation to be played at all which i am quite confused about. Preferably id like to get down to the reason this error is happening. Please let me know ๐Ÿ˜„

mossy tulip
#

Haven't tested NGO yet, but do you check if the client invoking the method is the owner?
You don't show it in your code but I assume you should have something like this in your code:

//...
if(IsOwner)
  NotifyServerOfActionAnimationServerRPC();
//...

I'm assuming you don't have the IsOwner check and you need it, otherwise non-owners would also invoke the serverrpc

pliant thorn
#

I believe your onto something :P.
Ive changed the code into this and now the host no longer gets the error but only the client lol!
To explain further when i roll on the clients game no errors pop up. But if i roll on the hosts game the client gets the same error.

mossy tulip
#

When I posted the code snippet I meant it on the ServerRPC method. The screenshot you sent has the suggestion applied but on the wrong place.

#

Could you sent the part of the code where you call the ServerRPC? Not the ClientRPC

pliant thorn
#

oh sorry i corrected that too but it doesnt play the animation for some odd reason which i believe is logic errors with my code

#

well it plays the animation locally

#

just not for the others

#

but i believe i do need to do what you said

mossy tulip
#

I find it kinda hard to provide further help without knowing the rest of the code. Perhaps could you share the entire script that's causing the erro?

pliant thorn
#

Its a bit of a mess rn since its what im implementing at the moment :P.
But essentially in my player locomotion script when i press the keybind it calls the roll method
which calls the roll in the player manager where i can communicate it to the animator manager
animator manager calls it in the network manager which calls the serverRPC.
Im kinda new to this so also lmk if theres a better way of handling so many scripts

#

the first image is in locomotion script

#

second is player manager

#

3rd is animator manager

#

4th is network manager script

#

ive added the isOwner to the 2nd image (the playermanager) which now gives me the problem of the animation not being seen by others

#

Ahhh!!!

#

ive fixed it ty very much @mossy tulip (apologies for the ping)

mossy tulip
#

I'm glad you found it ๐Ÿ˜„
I was just starting to check

#

what was it?

pliant thorn
#

in my animator manager i put a if(IsOwner) before it calls the ServerRPC

#

however !

#

is it wrong to make my animator manager a network behaviour just to do so

#

in fact i believe i can put this if statement before i even call the animator manager

#

ill just give it a go tweaking some things

mossy tulip
#

I mean, it kinda makes sense that the error is gone now since the script is not a network behaviour

pliant thorn
#

and i just put an if(IsOwner) before i call the serverRPC

#

my issue is that

#

when ur the player on ur game

#

u can freely call the animator manger play animation method

#

which plays the animation and calls the ServerRPC

#

howveer the serverRPC calls the clientRPC which then calls the same method in other players to do the same procedure

#

and since that method calls the ServerRPC but arnt the host on the local players game

#

it throws an error

mossy tulip
#

Ooooh I see, even tho when you put it that way it sounds more like it should cause an infinite recursion error

pliant thorn
#

Yep lmao!

mossy tulip
#

but just to be clear, you were using a IsOwner property on a non NetworkBehaviour script?

pliant thorn
#

i guess the error is saving me there :P.

mossy tulip
#

or were you getting the IsOwner from an external script?

pliant thorn
#

well i changed the animator manager to a network behaviour to use the IsOwner

#

before that i believe the only check if it was the owner was when it was listening for when the roll button was being pressed

#

which was on the player manager if i remever correctly

mossy tulip
#

oh okay I see

#

well. glad you figured it out ๐Ÿ˜„

pliant thorn
#

yep ty very much