• 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 Jonesy19 · Nov 15, 2016 at 04:08 PM · animationeditoreditor-scriptinganimationcliploop animaiton

How to edit Animation Clip Settings using an editor script

Hi Everyone, I'm trying to create an animation clip that loops using an editor script. I can do everything except loop the script. I have tried setting the wrapMode to WrapMode.Loop. I have also used AnimationUtility.Get/Set AnimationClipSettings. neither works...If I use the following code, I can see the "Loop Time" checkbox enabled in the inspector, but the animation does not loop. Is it a bug in Unity, or am I doing something wrong?

 AnimationClip newClip = new AnimationClip();
                         AnimationClipSettings acs = AnimationUtility.GetAnimationClipSettings(animClip);
                         AnimationClipSettings newSettings = AnimationUtility.GetAnimationClipSettings(newClip);
 
                         animClip.wrapMode = WrapMode.Loop;
                         newSettings.cycleOffset = acs.cycleOffset;
                         newSettings.heightFromFeet = acs.heightFromFeet;
                         newSettings.keepOriginalOrientation = acs.keepOriginalOrientation;
                         newSettings.keepOriginalPositionXZ = acs.keepOriginalPositionXZ;
                         newSettings.keepOriginalPositionY = acs.keepOriginalPositionY;
                         newSettings.level = acs.level;
                         newSettings.loopBlend = acs.loopBlend;
                         newSettings.loopBlendOrientation = acs.loopBlendOrientation;
                         newSettings.loopBlendPositionXZ = acs.loopBlendPositionXZ;
                         newSettings.loopBlendPositionY = acs.loopBlendPositionY;
                         newSettings.loopTime = true;
                         newSettings.mirror = acs.mirror;
                         newSettings.orientationOffsetY = acs.orientationOffsetY;
                         newSettings.startTime = acs.startTime;
                         newSettings.stopTime = acs.stopTime;
                         newSettings.additiveReferencePoseClip = acs.additiveReferencePoseClip;
                         newSettings.additiveReferencePoseTime = acs.additiveReferencePoseTime;
                         newSettings.hasAdditiveReferencePose = acs.hasAdditiveReferencePose;
                         
 
                         //ModelImporterClipAnimation blah = animClip as ModelImporterClipAnimation;
 
                         AnimationUtility.SetAnimationClipSettings(animClip, newSettings);
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Adam-Mechtley · Nov 16, 2016 at 09:51 AM

If "Loop Time" is true, that should be sufficient. Can you confirm that it remains ticked when the application starts playing (and the animation appears to not loop)

Comment
Add comment · Show 5 · 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 Jonesy19 · Nov 16, 2016 at 11:06 AM 0
Share

Hi Adam, thanks for the reply.

Yes, that is exactly how it is happening. If I run the code above from the editor, it ticks the "Loop Time" checkbox for the animation. When I press play, the animation plays once in the Scene/Game view, but does not play again. Interestingly, if I look at the animation state in the Animator window, I can see that it is trying to play on repeat (the status bar is looping for the animation state), but in the actual Scene/Game view, the animation is not looping.

Furthermore, if I simply uncheck and check "Loop Time" manually in the editor (with my mouse), it starts to play on loop. This seems like a Unity bug, but I was wondering if you had any thoughts...

Thanks...

avatar image Adam-Mechtley Jonesy19 · Nov 16, 2016 at 11:54 AM 0
Share

What kind of EditorScript is this happening in? E.g., AssetPostprocessor? You might try this and see if it makes a difference:

 Undo.RecordObject (animClip, "Change Settings");
 AnimationUtility.SetAnimationClipSettings (animClip, newSettings);
 EditorUtility.SetDirty (animClip);
avatar image Jonesy19 Adam-Mechtley · Nov 25, 2016 at 06:14 PM 0
Share

This is happening in an "EditorWindow" script (I hope that answers your question).

I tried your recommendation above, but it did not work. It did change something though - The check mark for Loop time is still checked, but now when I am viewing the animation, it does not loop, but it also does not look like it's trying to loop in the animator window either...(the blue line does not keep resetting).

Sorry for my delayed response also...I had to move off this issue to gain progress elsewhere...

Any thoughts? thanks for the help

Show more comments
avatar image
0

Answer by Jonesy19 · Dec 22, 2016 at 04:41 PM

I submitted a bug for this. The Case ID is 864049.

Thanks for the help Adam.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Animation Editor Window – Get Active Clip Info 1 Answer

How to get GameObjects used in AnimationClip 1 Answer

Instance gotten with reflection is throwing a null reference when trying to access its fields with reflection. 1 Answer

Trying to generate animation clips. 2 Answers

How to tell if an animation clip is playing in the editor(NOT in playmode) with an editor script 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges