• 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 BlastOffProductions · Feb 26, 2018 at 11:08 PM · errorcolliderserializationjavascript error

Error: GetComponentFastPath is not allowed?

BTY thanks in advance! So i'm getting this error saying:

GetComponentFastPath is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'KingCubisAPP'. See "Script Serialization" page in the Unity Manual for further details. UnityEngine.Component:GetComponent() KingCubisAPP:.ctor() (at Assets/Scripts Folder/KingCubisAPP.js:3) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

I know the code is sloppy, but it was working before on a previous version of Unity. Does anyone know what is wrong? Here's the java code that I use...

 #pragma strict
 
 private var animator = GetComponent.<Animator>(); 
 public var applyRootMotion;
  //var yourAnimation : Animation; // choose the animation which will start when triggered
  var FallerObject : GameObject; //Implement your Faller game object into this variable in the inspector
  //var After6 : GameObject;
 
  function Start (){
  animator.GetComponent(Animator);
  }
     
  function OnTriggerStart (Other : Collider){
   
  if(Other.gameObject.tag == "Player"){
           yield WaitForSeconds(1);
 
  FallerObject.GetComponent.<Animator>().Play("Up");
 GetComponent.<Animator>().applyRootMotion = false;
 animator.applyRootMotion = false;
 
 yield WaitForSeconds(2);
 Destroy (GameObject.FindWithTag("After6"));
 
 }
 }
 
Comment
Add comment · Show 1
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 FuzzyLogic · Feb 26, 2018 at 11:12 PM 1
Share

Format your question and your code so it's readable.

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by FuzzyLogic · Feb 26, 2018 at 11:35 PM

The problem is with the line:

 private var animator = GetComponent.<Animator>();

You cannot (usually) call a function when declaring a class variable because there's no guarantee that the Animator component exists yet at that time.

You need to assign the value to animator from the Start() or Awake() function as described in the error.

Something like:

  #pragma strict
  
 private var animator; 
 public var applyRootMotion;
 //var yourAnimation : Animation; // choose the animation which will start when triggered
 var FallerObject : GameObject; //Implement your Faller game object into this variable in the inspector
 //var After6 : GameObject;
  
 function Start (){
     animator = GetComponent.<Animator>();
 }
      
 function OnTriggerStart (Other : Collider){
    
     if(Other.gameObject.tag == "Player"){
         yield WaitForSeconds(1);
  
         FallerObject.GetComponent.<Animator>().Play("Up");
         GetComponent.<Animator>().applyRootMotion = false;
         animator.applyRootMotion = false;
  
         yield WaitForSeconds(2);
         Destroy (GameObject.FindWithTag("After6"));
  
     }
 }
Comment
Add comment · Show 1 · 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 BlastOffProductions · Feb 26, 2018 at 11:55 PM 0
Share

Thanks a lot! Both of the answers said are correct. BTY, thanks for re$$anonymous$$ding me to fix my question. : )

avatar image
1

Answer by Positive7 · Feb 26, 2018 at 11:25 PM

You can't use GetComponent in field initializer.

change private var animator = GetComponent.<Animator>(); to var animator : Animator; and in Start() :

 function Start() 
 {
     animator = GetComponent(Animator);
 }
Comment
Add comment · Show 1 · 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 BlastOffProductions · Feb 26, 2018 at 11:53 PM 0
Share

Thanks so much! Worked perfectly. You just saved my old project!

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

117 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

Related Questions

Error with trigger PLZ HELP!!!! 1 Answer

Failed to recompile android resource files. 1 Answer

Problem with GooglePlayServicesResolver 2 Answers

Cant turn on flashlight 1 Answer

Why isn't my java code working? 2 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