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
3
Question by Jay2645 · Feb 18, 2015 at 02:23 PM · animationanimation controllermechanimencapsulation

Changing Animation Controller at runtime?

Hello! I'm trying to encapsulate my game's weapons systems and I'm getting hung up on how to self-contain each weapon's character animations.

The goal is that I would be able to define any kind of weapon with a ScriptableObject containing the weapon parameters (model, projectile settings, muzzle flash settings, sound settings, etc.). In a "real" game, I would just create a WeaponData ScriptableObject, fill in the settings, then have everything just work.

I've gotten the majority of the work done, but I'm stuck on animations. I'm using humanoid Mechanim animations for everything, but I don't want to have to define every single possible weapon in one master AnimationController. Ideally, each weapon would have its own AnimationController containing just the animations for the use of that weapon, and if a player changes weapons I just replace the current weapon's AnimationController with the new weapon's AnimationController.

In a perfect world, I'd actually just like to replace one layer in the current AnimationController -- my "weapons" layer, which has a mask on it that allows my underlying walk animations to bleed through. However, if there's no way for me to just change one layer on an AnimationController, I'd be fine with having weapon-specific AnimationControllers and just swapping them out as needed (even if it means I would have to duplicate the underlying walk layer).

Now, I think I can simply just have my WeaponData ScriptableObject contain a reference to a regular AnimationController that I set up. When I swap weapons, I'd use Object.Instantiate to Instantiate that AnimationController as a RuntimeAnimationController, then assign that to my Animator. However, I have no idea if that's actually how it would work or if the RuntimeAnimationController needs to be some sort of special asset.

An alternative would be to use a AnimatorOverrideController, but I have no idea how that works or how I specify what clips I want to override. If I were to use a AnimatorOverrideController, I'd like to just have "unarmed" animations that I can override with weapon-specific animations as needed. The problem is I have no idea how AnimatorOverrideControllers work, and the documentation isn't very helpful (other than telling me that it can override clips in a controller to specialize animations for a certain avatar -- which sounds like what I want to do, but I'm not exactly sure). Would an AnimatorOverrideController be able to selectively override just my weapon animations? How would I tell it which animations I want to override, and which animations I want to override them with? Would it impact any animations that I don't want to override (i.e. walking)?

Hopefully I'm making some kind of sense here. Is my thinking correct, or is there a better way to handle this?

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 smoggach · Feb 18, 2015 at 02:31 PM 0
Share

Your idea sounds like it would work (with the runtimeAnimatorcontroller). Do you need to use the whole animator layer or just the clips? You can tell an animator to replace certain clips with other clips using an AnimatorOverrideController.

http://docs.unity3d.com/ScriptReference/AnimatorOverrideController.html

avatar image Glurth · Feb 18, 2015 at 03:20 PM 0
Share

http://docs.unity3d.com/ScriptReference/AnimatorOverrideController-clips.html

The clips array is a public array(visible in inspector) of animationclipPAIRs, stored in your AnimationOverrideController.

http://docs.unity3d.com/ScriptReference/AnimationClipPair.html

The animationclipPAIR: contains two clips, the original, and the one to override. So for each of your wepons the originalClip would be the same, and the override clip would be specific to the weapon.

0 Replies

· Add your reply
  • Sort: 

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

22 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

Related Questions

Animation Layer Weight Issue 1 Answer

How to nest Animation file in an Animation Controller? 1 Answer

Camera returns to starting position after playing animation 2 Answers

Dealing with multiple animations of the same kind 1 Answer

Precise animation control 4 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