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 YPZ · Mar 12, 2018 at 08:02 PM · editor-scriptingassetbundlefbxanimator controlleranimationclip

Avoid several prefabs' animations from looping at the same time when assigned to asset bundle

Unity version: 2017.3.0f3

Scenario: I have 4 fbxs imported in my proyect. With an editor script i create a new prefab from each of those. Then i dynamically create an AnimatorController for each new prefab, with the one clip that they all have. I then create a transition to itself to force it to loop since i cannot "check" the "Loop Time" checkbox from code nor the "Clamp Range" option. I also try to force the animation to play till the end by setting the transition to "HasExitTime = true" and "ExitTime = 1" After that i set the AssetBundle name and i create the bundle.


Issue: There are 4 prefabs in the bundle, two of them have an "animationClip.length" of 2 and the rest last for like 1.33. Still all of them "end" and start looping at time 1.33, the shortest among them.


Question: 1 - Why? 2 - How can i force their animations to loop at their respective end times correctly even after being bundled together?


This is my code after decomposing each prefab into an Object array, in order to be able to iterate through its components and get the animation clip, etc.

 foreach (Object[] item in lista) {
 
             AnimationClip clip = new AnimationClip ();
             GameObject mainObj = prefabs [lista.IndexOf (item)];
             Animator animator = null;
 
             //Obtain the animation clip
             foreach (Object obj in item) {
                 if (obj is AnimationClip) {
                     obj.name = mainObj.name + "clip";
                     clip = obj as AnimationClip;
                     Debug.Log ("Animation clip length > " + clip.length);
                 }
             }
 
             //Get the animator of the prefab to work with it
             UnityEditor.Animations.AnimatorController animatorController;
             animator = mainObj.GetComponent<Animator> ();
 
             //create an AnimatorController to later assign it inside the animator, based on the obtained clip
             string controllerPath = "Assets/Resources/CodeAnimControllers/" + mainObj.name + "controller.controller";
             animatorController = AnimatorController.CreateAnimatorControllerAtPathWithClip (controllerPath, clip);
 
             //Create a "false" parameter to the AnimatorController
             animatorController.AddParameter ("Reset", AnimatorControllerParameterType.Bool);
 
             //Get the only state machine, with its lone state and create a transition to itself
             var stateMachineA = animatorController.layers [0].stateMachine;
             var stateA = stateMachineA.states [0].state;
             var resetTransitionA = stateA.AddTransition (stateA);
 
             //Create the condition of reproduction, setting it to > play if Reset is false
             //Give an exit time to avoid endless restarting, the time is 1 so it completes its animation before restarting
             //Give itself no transition time for nice looping
             resetTransitionA.AddCondition (UnityEditor.Animations.AnimatorConditionMode.IfNot, 0, "Reset");
             resetTransitionA.canTransitionToSelf = true;
             resetTransitionA.destinationState = stateA;
             resetTransitionA.hasExitTime = true;
             resetTransitionA.exitTime = 1;
             resetTransitionA.duration = 0;
 
             //Asignar el controlador creado al objeto prefab
             animator.runtimeAnimatorController = animatorController as RuntimeAnimatorController;
 
             //Asignar un AssetBundle al prefab y su animatorController / Assign the AssetBundle name to the prefab and its animat                orController
             AssetImporter AI;
             string assetPrefabPath = AssetDatabase.GetAssetPath(mainObj);
             AI = AssetImporter.GetAtPath (assetPrefabPath);
             AI.assetBundleName = "otro";
 
             string assetPath = AssetDatabase.GetAssetPath(animatorController);
             AI = AssetImporter.GetAtPath (assetPath);
             AI.assetBundleName = "otro";
 
         }
         BuildPipeline.BuildAssetBundles (parentDirectory + "/" + newSubFolder, BuildAssetBundleOptions.None, BuildTarget.Android);



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

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

139 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

Related Questions

Any way to set AnimatorOverrideController's animation clips programatically? 1 Answer

AnimationClip length always equal 1 when prefeb is loaded from assetbundle with Unity5.3.2p1 1 Answer

[2D] Play animation backward. 1 Answer

Animation clips using different start value for Y 0 Answers

Camera animation clip stuck on first frame 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