- Home /
How to use an RPC to send an animation over the network?
I am working on a 2player (1v1) game, online thanks to Unity's native networking code and want to play an animation on a character for BOTH the host and the joiner. I searched around a little and read that I need to do it normally for the host, then use an RPC to send the updated info (saying to play the animation) to the joiner. However I didn't find any posts actually walking someone through this, and I do not know how to utilize RPCs yet.
Do I need any specific component on my main game object that holds all the scripts, is it just a simple line of code, or what?
Wow, that link was SUPER helpful, thank you!! Two quick questions..
1) I played around with it and noticed that any script can define an RPC function and any script can make the RPC call, regardless of the "focus" of the NetworkView component. Does the focus ever matter if I'm doing STRICTLY RPC's (no state sync), or should I just ignore it?
2) So I know how to call a basic function as an RPC function, but in part of my code, I have a coroutine that makes units turn to face a certain object. It waits for one unit to turn then makes the other, so in the code it looks like this:
yield return StartCoroutine(myCoroutine(firstUnit));
yield return StartCoroutine(myCoroutine(otherUnit));
How can I do THAT as an RPC function?
EDIT: added a 2nd question
1) it doesn't matter in this case, you may even set the synchronisation to off. All you need is a networkView on the object that is using RPCs
2) never done that our came across that, but I have two guesses: - send an RPC that starts a coroutine on the other client, so they work on both sides independently. Probably feasible if they produce consistent results, but some desynchronisation may occur. - have the side running the coroutine send state updates via RPC to the other client.
Though if it's about facing direction, isn't it an option to just synchronise the transform using networkView?
Answer by AyAMrau · Aug 26, 2014 at 09:49 PM
Have you read the RPC Manual? Since you can't just send an animation, so you will either need to pass it's name or some other value that will trigger a state change in the remote client (depends really on the setup in your game)
Answer by siddharth3322 · Aug 27, 2014 at 02:06 AM
You don't have to send any animation over network. It always play locally on any device. You have to communicate over all devices that it is a time to start playing animation.
You have to use RPC for this purpose only. So no jittering generates at all for your game.
Your answer
Follow this Question
Related Questions
[Error] RPC function undefined in IRRELEVANT file? 0 Answers
Multiplayer - Selected character to Network.guid? 0 Answers
Unity networking tutorial? 6 Answers
Testing my multiplayer character offline 0 Answers
RPCMode.AllBuffered Basic Question 1 Answer