Search Unity

cant find escene object in state machine behaviour

Discussion in 'Animation' started by Arcan-Studios, Nov 17, 2015.

  1. Arcan-Studios

    Arcan-Studios

    Joined:
    Mar 12, 2015
    Posts:
    49
  2. McGravity

    McGravity

    Joined:
    Nov 2, 2013
    Posts:
    43
    Could you provide some code?
     
  3. Arcan-Studios

    Arcan-Studios

    Joined:
    Mar 12, 2015
    Posts:
    49
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class prueba : StateMachineBehaviour
    5. {
    6.     public GameObject ob;
    7.     public GameObject prefab;
    8.  
    9.       //OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    10.     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    11.     {
    12.  
    13.         ob = GameObject.Find("Cube");
    14.         Instantiate(ob,Vector3.zero,Quaternion.identity);
    15.     }
    16.  
    17.     // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    18.     override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    19.     {
    20.        
    21.  
    22.     }
     
  4. McGravity

    McGravity

    Joined:
    Nov 2, 2013
    Posts:
    43
    And there is a GameObject called Cube in the Hierarchy? Have you debugged at this position? Does ob have any value after the Find method or is it null? (Not sure what happens when you instantiate a null value)
     
  5. Arcan-Studios

    Arcan-Studios

    Joined:
    Mar 12, 2015
    Posts:
    49
    sure is ther a gameobject called cube in the scene, noo need for debug, i make variable public, and the reference in the inspector still null after press start
     
  6. McGravity

    McGravity

    Joined:
    Nov 2, 2013
    Posts:
    43
    Okay, next question. Is the state executed to which this SMB is attached to?
     
  7. Arcan-Studios

    Arcan-Studios

    Joined:
    Mar 12, 2015
    Posts:
    49
  8. Arcan-Studios

    Arcan-Studios

    Joined:
    Mar 12, 2015
    Posts:
    49
    indeed i prove to make an instantiate with an prefab and it work, doesnt work only with scene object
     
  9. McGravity

    McGravity

    Joined:
    Nov 2, 2013
    Posts:
    43
    Well, then it should work. Can you make a screenshot of your cube GameObject and your animator controller (best from the Animator view where you have the specific node selected)?
     
  10. Arcan-Studios

    Arcan-Studios

    Joined:
    Mar 12, 2015
    Posts:
    49
    thats the problem it should work, but it doesnt
     

    Attached Files:

  11. Arcan-Studios

    Arcan-Studios

    Joined:
    Mar 12, 2015
    Posts:
    49
    i just upload the project, please help me
     

    Attached Files:

  12. McGravity

    McGravity

    Joined:
    Nov 2, 2013
    Posts:
    43
  13. Arcan-Studios

    Arcan-Studios

    Joined:
    Mar 12, 2015
    Posts:
    49
    thanks very much, now its working, and dont know why, maybe for restarting unity, anyway thanks a lot i study the tutorial
     
unityunity