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

Playable graph is destroying my C# class.

Discussion in 'Visual Scripting' started by mountblanc, Apr 26, 2022.

  1. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    93
    Something strange is happening.
    I have Enter Playmode settings turned on and Reload Domain and Reload Scene turned off.

    My scene has a player containing a few scripts for animations and stuff.
    The main script on the main Object is listening to EventBus events:
    Code (CSharp):
    1.         EventBus.Register<int>(EventNames.Player_TurnLeft,TurnLeft);
    2.             EventBus.Register<int>(EventNames.Player_TurnRight,TurnRight);
    3.             EventBus.Register<int>(EventNames.Player_Up,MoveUp);
    4.             EventBus.Register<int>(EventNames.Player_Down,MoveDown);
    5.             EventBus.Register<int>(EventNames.Player_Forward,MoveForward);
    6.             EventBus.Register<int>(EventNames.Player_Backward,MoveBackward);
    7.             EventBus.Register<int>(EventNames.Player_TurnStop,Stop);
    taking one of the methods as example:
    Code (CSharp):
    1.         private void Stop<TArgs>(TArgs obj)
    2.         {
    3.             if (m_bAirBorn)
    4.             {
    5.                 SetRockets(RocketsStatus.MainIdle);
    6.                 return;
    7.             }
    8.  
    9.             SetWheels(WheelStatus.Idle);
    10.         }
    11.  
    12.         private void SetWheels(WheelStatus status)
    13.         {
    14.             if (m_wheelStatus == status)
    15.                 return;
    16.  
    17.             switch (status)
    18.             {
    19.                 case WheelStatus.Backward:
    20.                 {
    21.                     m_aWheelTracksLeft[0].MoveBackward();
    22.                     m_aWheelTracksLeft[1].MoveBackward();
    23.                     m_aWheelTracksRight[0].MoveBackward();
    24.                     m_aWheelTracksRight[1].MoveBackward();
    25.                     break;
    26.                 }
    27.  
    28. etc......
    The m_aWheels is defined as follows:
    Code (CSharp):
    1.        [SerializeField]
    2.         private WheelTrackController[] m_aWheelTracksLeft;
    And is in the inspector linked to child objects containing does C# classes.

    Now i have a Visual Script just for quickly sending some keystrokes to make them send out messages over the EventBus:
    upload_2022-4-26_18-31-47.png

    The code for the custom event does this:
    Code (CSharp):
    1.        //Sending the Event MyCustomEvent with the integer value from the ValueInput port myValueA.
    2.         private ControlOutput Trigger(Flow flow)
    3.         {
    4.             EventBus.Trigger(flow.GetValue<string>(myString),1);//, flow.GetValue<int>(myValue));
    5.             return outputTrigger;
    6.         }    
    If i run the scene for the first time all is OK. But running a second time my WheelTrackControlles are destroyed??
    upload_2022-4-26_18-42-5.png
    I added a method and a breakpoint to track the method that destroyed them and it turns out to be :
    Code (CSharp):
    1.     [RequiredByNativeCode]
    2.     private static void OnDestroyingPlayableGraph(PlayableGraph graph)
    3.     {
    4.       if (Utility.destroyingGraph == null)
    5.         return;
    6.       Utility.destroyingGraph(graph);
    7.     }
    8.  
    I really do not understand why? The Graph only has the event class and is not linked in any way to the Wheeltracker controls.

    I listen to the events with a different class. If any class would be destroyed it should be that one.

    (p.s. If I have Playmode settings turned off all is ok but thats not the point)

    Why would a ScriptGraph Destroy C# classes it has no link to and HOW is this even alowed ?

    Anyone have any idea ? thanks!
     
  2. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    93
    Hmmm it seems objects are destroyed and recreated all over the place. I have to tinker more.. Cant delete this post so will give an update when i find out more. (I asumed incorrectly that stuff would not be destroyed it seems)
     
  3. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    93
    Ok now i found the part that made everything go boom. Aldo i still do not know why.
    I have the following debug message in one of the evens:
    Code (CSharp):
    1.             #if DEBUG
    2.                  Debug.Log(this.name + " : Stopped animations.");
    3.             #endif
    if i remove this.name all is ok.
    Well at least the error is gone. i find it still strange.

    If I keep it, my m_aWheeltracks are destroyed (In parent class) after reRun.
    upload_2022-4-26_19-16-4.png

    and if i remove this.name from de debug message they are not destroyed if I reRun.
    upload_2022-4-26_19-14-49.png

    So i am realy confused even more.
     
  4. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    93
    I did some more tests and the errors only accurses when an EventBus is Triggered inside a Visual Script. Only then the error accurse. Firing the same EventBus trigger outside the Visual graph is fine.
    I made a very small example project and filled a bug rapport Case 1423788.

    I found also an other bug when you try to check if an EventHook is set:.
    This throws an "ArgumentNullException" because checking it results in an empty EventBus.Trigger with a null string.
    So Ironically the check itself throws an exception you try to prevent in the first place.

    Code (CSharp):
    1.  
    2. if (m_eventHook != null)
    3. {
    4.             EventBus.Trigger(m_eventHook, 1);
    5. }
    case 1423800