Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Xatoku · Oct 11, 2011 at 09:50 PM · animationmultiplayernetworksynchronization

Multiplayer Animating

I've got my multiplayer script working properly so I can move around characters over the internet, but I'm not seeing any animation in the character opposite to my connection. I'm a total noob to networking and only barely managed to get the initial framework going, so would anyone mind helping me out?

I've checked around and haven't been able to see any basic information on synchronizing character animation with one another. If I put 2 Network Views on a character - one with the transform and the other with the animation, animations will play but they will be the wrong animations and clip in/out randomly. Could somebody just lay down the basics on integrating character animation over a network for me?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image asafsitner · Oct 11, 2011 at 10:04 PM 0
Share

Forget about synchronizing animations through network views - it's a complete mess and really heavy on the network bandwidth.

Ins$$anonymous$$d what you should do is synchronize a the animation's play state. See here:

http://unity3d.com/support/documentation/Components/net-$$anonymous$$inimizingBandwidth.html

avatar image Xatoku · Oct 12, 2011 at 06:17 AM 0
Share

I'm still confused. I know very little about networking as I said before. I'm just looking for an example to work from to get the gist of it.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by asafsitner · Oct 12, 2011 at 10:40 AM

Right. So you have a networkView with a certain ID. It needs to be the same ID over all network instances of your game for it to synchronize correctly. You set it to watch your animation script, not the animation component. In the script you'll have a variable, it could even be a bool, that represents the animation's state. And possibly a char that represents the animation ID, if you have more than one animation. In the method OnSerializeNetworkView you write and read these values to/from the network. Something like this, probably (c#):

 void OnSerializeNetworkView (BitStream stream, NetworkMessageInfo info)
     {
         //this is what we serialize TO the network
         if (stream.isWriting)
         {
             bool sendPlayState = playState;
             char sendAnimID = animID;
             
             stream.Serialize(ref sendPlayState);
             stream.Serialize(ref sendAnimID);
         }
         //this is what we serialize FROM the network
         else
         {
             bool receivePlayState = false;
             char receiveAnimID = 0;
 
             stream.Serialize(ref receivePlayState);
             stream.Serialize(ref receiveAnimID);
 
             playState = receivePlayState;
             animID = receiveAnimID;
         }
     }
Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Xatoku · Oct 12, 2011 at 03:57 PM 0
Share

So if I put this onto the character and then into the network view, would I have to tell the animations to tell this script that they're animating? Also, if the Network View is covering the animation script, should I also get a script for covering position/rotation, or just have 2 Network Views on the object?

avatar image Xatoku · Oct 12, 2011 at 05:28 PM 0
Share

Well your answer worked pretty flawlessly. I tweaked the code a bit to recognize my specific animations, but it works! I also added another Network view to look after transform position/rotation but it seems a bit wrong to have 2 Network Views on the same object. Is there another way to have it see both animation & posiiton/rotation?

avatar image asafsitner · Oct 12, 2011 at 05:29 PM 0
Share

Yes, you would need your script to 'talk' to the animations and figure out which one is playing right now. And yes, you should have 2 Network Views for the object. It could get a little tricky managing viewID's for multiple Network Views, but it's far more efficient to synchronize chars and bools than synchronizing the animation itself.

avatar image Xatoku · Oct 12, 2011 at 06:47 PM 0
Share

Alright, thanks a ton man, you've really helped me out! One last question though just out of curiosity. Do I need network views for each component I want seen? Like a Particle System for example, would that need 3 Network Views for the Emitter, Animator, and Renderer?

EDIT: Also, is there any control over layers within the network? Because most of my animations that only play once are layered to play on top of the looping animations so now because it's only translating animation data and not layers, it won't play the layered animations.

avatar image asafsitner · Oct 12, 2011 at 08:42 PM 0
Share

That depends on how your scene is built and how you use particles, but I think the same principle of synchronizing animations should work with particles. I mean, you should have the game object that has the particle effect component instantiated over the network, so why not synchronize the emitter's 'enabled' state?

And if it's a one-time particle effect that is instantiated in run-time, you could use an RPC call to instantiate it over the network, or, alternatively, use Network.Instantiate. $$anonymous$$ake sure you keep your RPC buffer clean and organized though - you wouldn't want new players to receive irrelevant instructions (for example, if you have a rocket explode and instantiate the explosion over the network, if you don't remove it from the buffer every time a player joins the game they'll see all the explosions that have happened since the game started).

As for animations and layers - that depends on the script that controls the animations. You can't serialize arrays over the network, so in case you have a lot of animations you'll probably want to develop a system to automatically deter$$anonymous$$e which animations should be played and on which layer and only synchronize that data over the network. $$anonymous$$aybe hold some arrays of animations, one for 'base' animations like walking or running and one for 'added' animations like reloading a weapon, and serialize the animations's positions in the arrays, then only played the animation whose position you received from the network in the last update.

You could probably think of a better approach more properly suited for your needs, though, it's just an idea.

Show more comments
avatar image
0

Answer by aleems · Dec 12, 2011 at 11:17 AM

but to in which script i have to include above one... am adding the above one in third person controll script.. is it right..

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Animation state Synchronization in Multiplayer 1 Answer

Network animations 2 Answers

Networking Animation problem 1 Answer

Network Animator not syncing with Clients in Netcode 0 Answers

Simple Multiplayer Animation Question 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges