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 /
This question was closed Mar 07, 2015 at 10:02 PM by KnightRiderGuy for the following reason:

Solved it by putting animation manager script on each UI panel that was to be animated.

avatar image
0
Question by KnightRiderGuy · Feb 16, 2015 at 01:09 AM · animationuianimatorerror messageanimations

Invalid Layer Index?

OK this is weird, I have two animations that I start from a C# script, the animations are fine and they work OK but one of them will not play in my UI interface set up? I get the following error:

Invalid Layer Index UnityEngine.Animator:Play(String) ScannerAdjustmanager:StartScannerLights() (at Assets/ScannerAdjustmanager.cs:42) UnityEngine.EventSystems.EventSystem:Update()

In my inspector I have the Animator Unchecked and my C# script is supposed to activate them when I press a UI button, but only one of them works, and I get that error message above? I'll post my script just incase anyone can see something I'm missing.

 using UnityEngine;
 using System.Collections;
 
 public class ScannerAdjustmanager : MonoBehaviour {
 
     //Reference to Animations
     public GameObject ScannerLightAni;
     public GameObject BlueLEDsAni;
 
     //Audio Clip References
     public AudioClip Scanner;
 
     //animator reference
     private Animator anim;
 
     void Start () {
         //unpause the game on start
         //Time.timeScale = 1;
         //get the animator component
         anim = ScannerLightAni.GetComponent<Animator>();
         anim = BlueLEDsAni.GetComponent<Animator>();
         //disable it on start to stop it from playing the default animation
         //anim.enabled = false;
     }
 
 
 
     public void  GoAbort(){
         StartCoroutine(LoadAfterDelay("ThreeD_Overview"));
     }
     
     IEnumerator LoadAfterDelay(string levelName){
         yield return new WaitForSeconds(0.5f); // wait 1 seconds
         Application.LoadLevel(levelName);
         
     }
 
     //Start Scanner Animations
     public void  StartScannerLights(){
         //StartCoroutine(AutoDoorOutR());
         anim.enabled = true;
         anim.Play("ScannerAdjustAnimation");
     }
 
     //Start LEDs Animations
     public void  StartLEDLights(){
         //StartCoroutine(AutoDoorOutR());
         anim.enabled = true;
         anim.Play("ScannerBlueLEDsAni");
 
         //Audio Play
         audio.clip = Scanner;
         audio.loop = true;
         audio.Play();
     }
 }
 
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

  • Sort: 
avatar image
0

Answer by meat5000 · Feb 16, 2015 at 01:16 AM

It wants more information. Layer and Normalised Time.

http://docs.unity3d.com/ScriptReference/Animator.Play.html

It appears you are trying to use it the Legacy way.

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 KnightRiderGuy · Feb 16, 2015 at 01:35 PM 0
Share

Well, I have no clue what that meant, but I did discover that if I made a separate script for each animation and called them from my UI buttons and that solved the problem.

avatar image meat5000 ♦ · Feb 16, 2015 at 01:39 PM 0
Share

It says Invalid Layer Index because according to the page I linked

animator.Play wants you to tell it what layer the state is in you are trying to play.

But I almost told you lies, it does support a string.

avatar image KnightRiderGuy · Feb 16, 2015 at 01:54 PM 0
Share

It was confusing me because they were all on the UI layer which would make sense to me, but for some reason it just did not like my calling it from the same script, soon as I made a separate script and dragged that onto the animation and then dragged the animation onto my UI button it worked.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Animation not looping 1 Answer

Create animation transitions via script. 0 Answers

Mirroring animation clip without mirroring root motion node? 0 Answers

The animation does not play when I click 2 Answers

Wierd flickering animation 1 Answer


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