Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

StateMachineBehaviour returning null in 1.1.7

Discussion in 'Addressables' started by faolad, Aug 6, 2019.

  1. faolad

    faolad

    Joined:
    Jan 27, 2013
    Posts:
    118
    It happens on Windows Standalone, it doesn't show up in Packed Play Mode.
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Gonna need some additional context here. Don't really know what you're describing.
     
  3. faolad

    faolad

    Joined:
    Jan 27, 2013
    Posts:
    118
    Sorry, most of my threads are done in a deadbeat mode >.<

    Somewhere in the process, the reference to the StateMachineBehaviour on the game gets lost.

    Goes like this, If I have Object A with OtherScript and Object B with a reference to an Object with animator and ExampleBehaviour attached to an animator state. When Object A try to GetBehavior from B it returns null.

    Code (CSharp):
    1. public class ExampleBehaviour : StateMachineBehaviour
    2. {
    3.     public GameObject clone;
    4.  
    5.     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    6.     {
    7.        OtherScript otherScript = clone.GetComponent<OtherScript>();
    8.        otherScript.DoSomething();
    9.     }
    10. }
    Code (CSharp):
    1. public class OtherScript  : Mono
    2. {
    3.     public Animator animator;
    4.  
    5.     public void Start()
    6.     {
    7.        animator = objectwithAnimator.GetComponent<Animator>();
    8.  
    9.    
    10.        //this doesn't work
    11.        animator.GetBehaviour<ExampleBehaviour>().clone = this;
    12.     }
    13.     public void DoSomething()
    14.    {
    15.    //
    16.     }
    17. }
     
    Last edited: Aug 8, 2019
  4. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    I'm not super familiar with animators, but I think you meant to call GetBehaviour not GetComponent
     
    danilonishimura likes this.
  5. faolad

    faolad

    Joined:
    Jan 27, 2013
    Posts:
    118
    yeah sorry, its GetBehaviour where the issue is.
     
  6. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    So it is still broken with GetBehaviour?

    We'll try to repro it, but it would really help to get a repro project. If you can make one, file a bug against Unity and put the ticket number in this thread.
     
  7. melissae

    melissae

    Unity Technologies

    Joined:
    Dec 5, 2018
    Posts:
    9
    @faolad - if you can get us an existing sample project we could follow up. Because we are not sure where objectwithAnimator is being loaded from.
     
  8. faolad

    faolad

    Joined:
    Jan 27, 2013
    Posts:
    118
    I can't recall, but in some version, the error was fixed, sorry. Not sure if it was that or the fact that we start using assembly definitions. Trying to pinpoint where was that being shown seems very time consuming for us to give it a try.
     
  9. melissae

    melissae

    Unity Technologies

    Joined:
    Dec 5, 2018
    Posts:
    9
    @faolad - thank you for the update.
     
    faolad likes this.