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 /
avatar image
0
Question by The-Gaming-Seed · Feb 23, 2017 at 10:03 AM · c#animationanimatordebug

Playing animation at the start

The animation plays at the start however when i leave the scene and come back, the animation does not play. It's marked as legacy and i've tried to use code:

 public GameObject The_Cam;

 void Start()
 {
     Screen.SetResolution (1920, 1080, true);
     The_Cam.GetComponent<Animation>().Play();

 }

ignore the Screen.SetResolution (1920, 1080);

I'be used the animator component and used the animation component but both does not work.

The animation is on a camera

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
1

Answer by UnityCoach · Feb 23, 2017 at 12:07 PM

The Animation component has a default animation slot. Make sure the animation you want to play is assigned to it. You can also try this :

 Debug.Log ( The_Cam.GetComponent<Animation>().Play() );

If it returns false, it means there's no default animation to be played.

You can also force it to play the animation, passing the animation name, like :

 The_Cam.GetComponent<Animation>().Play("AnimationName");
Comment
Add comment · Show 3 · 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 UnityCoach · Feb 23, 2017 at 12:10 PM 0
Share

And if you were to use Animator ins$$anonymous$$d, which I would recommend, you pass it the name of the state (not the animation).

 The_Cam.GetComponent<Animator>().Play("StateName");
avatar image The-Gaming-Seed · Feb 23, 2017 at 06:40 PM 0
Share

I've tried the two above and both don't work. The top one comes as True but still doesn't play the animation and the second does nothing for some reason. I've tried the last one with the animator and does not work for some reason.

avatar image UnityCoach The-Gaming-Seed · Feb 23, 2017 at 07:04 PM 0
Share

Did you import the animation from an FBX file or is it an animation you made in the editor?

Just looked at the Animation documentation and found it has a legacy property that must be set to true for the animation clip to be used with the Animation component. So, if you haven't already, this may fix the problem.

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

9 People are following this question.

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

Related Questions

Set boolean to false when animation changes? 1 Answer

Animating multiple objects that should interact with eachother 0 Answers

Animation works only once when button pressed 1 Answer

How to play mecanim animations in Editor mode? 2 Answers

transform.position not setting position OR animation setting position even though it shouldn't 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