Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by DustinBoyle · Apr 28, 2017 at 07:07 PM · networkinganimatorcharacteravatar

Why is my Avatar getting unassigned from the Animator at runtime?

I am building a multi-player networked game. When I spawn my character at runtime the avatar gets unassigned from the Animator.

I can re-apply the reference manually and the character will animate, Unfortunately, Animator.Avatar is not fully supported and Unity advises to use it at your own risk.

Why is this happening? I am having trouble finding any sort of fix.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ADAMN721 · Apr 28, 2017 at 08:09 PM

I have had a similar problem before with my networked game and ended up discovering it was because the item I was referencing wasn't attached to my player. For networked games, any item you are assigning in the inspector has to be a part of that prefab or it will lose it's reference when the player is instantiated. For example, if you have a static object in the scene such as a cube. You can't have a reference that you drag and drop in the inspector for your player on that item.

In your scenario that may not apply but you can always assign it through script at runtime. Try implementing an Awake() method and assigning it in there.

Comment
Add comment · Show 6 · 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 DustinBoyle · Apr 28, 2017 at 08:18 PM 0
Share

Thanks for the quick reply,

I made the same assumption, but assigning at runtime does not seem to be working. Here is my code, your help is appreciated:

     public Avatar Robot$$anonymous$$yleAvatar;
     private Avatar avatar;

     void Awake()
     {
         anim = GetComponent<Animator> ();
         avatar = anim.GetComponent<Avatar> ();
         avatar = Robot$$anonymous$$yleAvatar;
     }
avatar image ADAMN721 DustinBoyle · Apr 28, 2017 at 08:41 PM 0
Share

So for assigning at runtime you want to make sure that you are referencing the correct place in the hierarchy. Currently, you are saying the animator component is on the same level your script is on, is this correct? If your animator is on a lower or higher level of the prefab, this will fail to assign.

For an example, say the script is on the top level of your player and the animator is attached to a child gamobject of that player. You would need to use GetComponentInChildren() in that case.

Side note: I noticed you have a public and a private variable. You could just make one private variable and use [SerializeField] attribute which will force unity to serialize a field for it in the inspector.

avatar image DustinBoyle ADAMN721 · Apr 28, 2017 at 08:57 PM 0
Share

The animator is on the same level as the script. There is no example in the API of how to assign an avatar via script.

$$anonymous$$y public Avatar is the robots avatar while my private Avatar is the Avatar component of the Animator.

Is this method incorrect?

Show more comments
avatar image DustinBoyle DustinBoyle · Apr 28, 2017 at 09:24 PM 0
Share

So it is a humanoid rig, and it does animate correctly. The problem only occurs when I spawn the network character. As soon as it is spawned the avatar is unassigned.

During runtime, I can manually drag the avatar onto the animator and the character begins to animate.

Although the rig is humanoid, the avatar does not auto assign its self.

avatar image DustinBoyle DustinBoyle · Apr 28, 2017 at 09:49 PM 0
Share

HI @ADA$$anonymous$$N721 I tried adding the character to the scene without spawning it. Since there are network components on the character it becomes inactive at runtime.

As soon as a check the box to enable the character, the avatar gets unassigned. When I remove the network components the problem is gone.

Any idea of what might be happening here?

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

144 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Character falls when animator plays 0 Answers

Is it possible to use an 3d Animation with Anima2D? 1 Answer

Replace / Modify Humanoid Avatar during Runtime 0 Answers

Is it possible to use Dinamicaly generated characters instead of prefabs in/for NetworkManager? 0 Answers

NETWORK: Animator probleme. Unity 4.6.3.f1 0 Answers


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