Forum rules - please read before posting.

[Bug] Error when deactivating a trigger's parent

Hello, back in September I made this thread about an error thrown when deactivating a Trigger from another Trigger : https://adventurecreator.org/forum/discussion/16249/bug-error-when-deactivating-a-trigger-object-from-another-trigger#latest

Today I have to report a similar issue with an error being thrown when directly deactivating (whether in the inspector or through an Action List) the parent of a trigger :

The tricky part is that while I can clearly show it in this level of my game, I can't reproduce it in the AC Basement demo scene, even though I SWEAR I had the same error when deactivating the Logic object on first try ! I also tried to reproduce the bug in a new fresh scene with a single trigger in my personal project but it didn't happen. In the meantime, I can still share the stack and source of the error :

[Error] Coroutine couldn't be started because the the game object 'Corner_CamSwitch2_2' is inactive!
MonoBehaviour.StartCoroutine()

ActionList.ProcessAction() at /AdventureCreator/Scripts/ActionList/ActionList.cs:419
 417:     {
 418:        // Run it
--> 419:        StartCoroutine (RunAction (actions[i]));
 420:     }
 421:  }

ActionList.BeginActionList() at /AdventureCreator/Scripts/ActionList/ActionList.cs:388
 386:     if (KickStarter.actionListManager.IsListRegistered (this))
 387:     {
--> 388:        ProcessAction (i);
 389:     }
 390:  }

ActionList.Interact() at /AdventureCreator/Scripts/ActionList/ActionList.cs:289
 287:        ResetList ();
 288:        ResetSkips ();
--> 289:        BeginActionList (i, addToSkipQueue);
 290:     }
 291:  }

ActionList.Interact() at /AdventureCreator/Scripts/ActionList/ActionList.cs:252
 250:  public virtual void Interact()
 251:  {
--> 252:     Interact(0, true);
 253:  }

AC_Trigger.Interact() at /AdventureCreator/Scripts/Logic/AC_Trigger.cs:340
 338:     }
--> 340:     base.Interact ();
 341:  }

AC_Trigger/PositionDetectObject.Process() at /AdventureCreator/Scripts/Logic/AC_Trigger.cs:661
 659:     if (trigger.IsObjectCorrect (obToDetect))
 660:     {
--> 661:        trigger.Interact (obToDetect);
 662:     }
 663:  }

AC_Trigger._Update() at /AdventureCreator/Scripts/Logic/AC_Trigger.cs:99
  97:     for (int i=0; i<positionDetectObjects.Count; i++)
  98:     {
-->  99:        positionDetectObjects[i].Process (this);
 100:     }
 101:  }

StateHandler.Update() at /AdventureCreator/Scripts/Game engine/StateHandler.cs:268
 266:     for (int i = 0; i < Triggers.Count; i++)
 267:     {
--> 268:        Triggers[i]._Update ();
 269:     }
 270:  }

I hope this piece of information can nonetheless help us get started, let me know if I should try something specific to reproduce the issue. Thanks.

Comments

  • In your video's empty project, use the New Game Wizard to create a new set of Managers for a 3D game, with the Sample 3D Player, but no Sample 3D Scene.

    Then, copy over the scene file with the issue and run it in the empty project. Putting aside any other issues (visual glitches, missing prefabs etc), does the Trigger issue occur there as well?

    If so, PM me the scene file.

  • Hi, yes that was a good suggestion and I was able to reproduce the bug, I'll send you the scene file in DM. One thing I'll add here is that when looking at the issue again in my main project, I deleted a bunch of triggers and objects in the scene, and still got the issue, then duplicated the two triggers mentioned in the error logs and deleted the original ones, which for some reason solved the issue !

    Still, that can't be a real fix, I hope that my files aren't corrupt deep down or something like that, in any case I'll hope you'll be able to help me out with the scene file !

  • I cannot reproduce it with the scene file you've sent.

    The error messages above suggest a Trigger is being entered, but none of them are near enough to the Default PlayerStart that they'd be fired by the Player's presence. Is there another object at play?

  • When looking at the repro scene again today, I was unable to reproduce the issue myself :o

    Nonetheless, I looked again at the call stack and found the root of the issue in AC_Trigger.CheckForPoint - specifically the ClosestPoint part. I asked ChatGPT about it and his reply was I think useful : https://chatgpt.com/share/691629c5-5c68-800b-a696-d83396a8f8dd

    Here's also a new video I made :

    So if I have to avoid deactivating the parent object and instead just disable all of the children colliders, I'll figure something out. Beside, the parent and its children can be deleted altogether without an error, which makes things simpler in the context of a linear game like mine. Nonetheless, it would be awesome if some failsafe could be added on AC's side to save other devs using many triggers with the transform detection method a headache. Thanks as always.

  • Where is the Player in relation to the Trigger? If the Trigger is above or below, the returned value may well be correct.

    What was the underlying discovery you made that led you to this line?

  • I just took at the call stack, the second call just before the interact one had to have something to do with it. In the video I made yesterday the trigger was 20 units behind the player on the Z axis, but I still got the error when I moved the trigger parent far away on all axes - the closest point returned the player's position.

    But it turns out the fix for this is very simple and I had made a rookie mistake - in AC_Trigger._Update, we can add a simple if statement like this :

                        if (gameObject.activeInHierarchy)
                        {
                            positionDetectObjects[i].Process(this);
                        }
    

    I had initially tried with activeSelf instead of activeInHierarchy, that's why it didn't work ! Could this be applied to the base code ? I assure you I got the bug once in the Basement demo and in the repro file I sent you, so that would likely save other devs the same headache.

  • Replace the _Update function with the below. If it works, I'll make the same change to the official release:

    public void _Update ()
    {
        if (detectionMethod == TriggerDetectionMethod.TransformPosition && gameObject.activeInHierarchy)
        {
            for (int i=0; i<positionDetectObjects.Count; i++)
            {
                positionDetectObjects[i].Process (this);
            }
        }
    }
    
  • Yes, it works :smile:

  • Oh well, this fix actually leads to an error when we delete the trigger parent !

    [Exception] MissingReferenceException: The object of type 'AC.AC_Trigger' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject() at <038ae34513ab4db49caf29025be8f045>:0
    
    ThrowHelper.ThrowNullReferenceException() at <038ae34513ab4db49caf29025be8f045>:0
    
    Component.get_gameObject() at <038ae34513ab4db49caf29025be8f045>:0
    
    AC_Trigger._Update() at /AdventureCreator/Scripts/Logic/AC_Trigger.cs:94
      92:        public void _Update ()
      93:        {
    -->  94:              if (detectionMethod == TriggerDetectionMethod.TransformPosition && gameObject.activeInHierarchy)
      95:              {
      96:                  for (int i = 0; i < positionDetectObjects.Count; i++)
    
    StateHandler.Update() at /AdventureCreator/Scripts/Game engine/StateHandler.cs:268
     266:     for (int i = 0; i < Triggers.Count; i++)
     267:     {
    --> 268:        Triggers[i]._Update ();
     269:     }
     270:  }
    

    We can prevent that simply by checking if the trigger is null, by just adding this to the if statement :

    this != null
    

    Could you please add that to the official code as well ? Thanks.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.