Forum rules - please read before posting.

Load Problem with Triggers

Hi Chris!

How are you? Team Cultic is back with another question for the benefit of “Cats and the Other Lives” :)

In our game, we save every scene on On Start Action List. After Loading scene on On Load Action List we use Engine:End Game - Reset Scene Action. We did a couple optimization changes like;

But, we have captured a problem with Triggers that causes a pretty disturbing crash/freeze when we try to load a scene that the trigger is used. When scene is started and player Load the game immediately everything works perfectly.

But, when player enters into the trigger and (The first action of the trigger is Custom:Trigger Enable or Disable - Default and disable self ) while ActionList is running and try to load the game, the game crashes (The game crash even if the Action is Finished). I thought the custom action causes this problem but, after I did some research on the forums, I found this discussion: https://adventurecreator.org/forum/discussion/7593/what-is-the-best-way-to-disable-or-remove-a-trigger-after-its-played

So tried that solution and disabled the Trigger with Objects:Send Message but the problem still there. Nothing has changed. Do you have any solution to this problem? This really became a blockage for us since we used that disable function very often throughout the game. Thanks a lot man! Looking forward to your answer.

AC_TriggerEnableDisable.cs

using UnityEngine;
using System;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC
{

    [System.Serializable]
    public class AC_TriggerEnableDisable : Action
    {
        public enum State { Default, CustomAsset, DisableAll}
        public State _state = State.Default;

        public AC_Trigger _trigger;
        public GameObject _triggerAsset;
        public int state = 1;

        public int constantID;
        public int parameterID = -1;

        public int defaultParameterID = -1;
        public int defaultConstantID;

        public AC_TriggerEnableDisable()
        {
            this.isDisplayed = true;
            category = ActionCategory.Custom;
            title = "Trigger Enable or Disable";
            description = "Change State of Trigger.";
        }

        public override void AssignValues(List<ActionParameter> parameters)
        {
            _triggerAsset = AssignFile(parameters, parameterID, constantID, _triggerAsset);
            _trigger = AssignFile(parameters, defaultParameterID, defaultConstantID, _trigger);
        }

        public override float Run()
        {
            if(_state == State.Default)
            {
                switch (state)
                {
                    case 0:
                        _trigger.TurnOff();
                        break;
                    case 1:
                        _trigger.TurnOn();
                        break;
                }
            }
            else if(_state == State.CustomAsset)
            {
                switch (state)
                {
                    case 0:
                        _triggerAsset.GetComponent<AC_Trigger>().TurnOff(); // 0 = TurnOff Trigger
                        break;
                    case 1:
                        _triggerAsset.GetComponent<AC_Trigger>().TurnOn(); // 1 = TurnOn Trigger
                        break;
                }
            }
            else if(_state == State.DisableAll)
            {
                AC_Trigger[] _trigger = FindObjectsOfType<AC_Trigger>();

                foreach(AC_Trigger t in _trigger)
                {
                    t.TurnOff();
                }
            }


            return base.Run();
        }

#if UNITY_EDITOR

        public override void ShowGUI(List<ActionParameter> parameters)
        {
            _state = (State)EditorGUILayout.EnumPopup("State: ", _state);
            if (_state == State.Default)
            {
                defaultParameterID = Action.ChooseParameterGUI
                ("Trigger: ", parameters, defaultParameterID, ParameterType.GameObject);
                if(defaultParameterID >= 0)
                {
                    defaultConstantID = 0;
                    _trigger = null;
                }
                else
                {
                    _trigger = (AC_Trigger)EditorGUILayout.ObjectField
                        ("Trigger", _trigger, typeof(AC_Trigger), true);
                    defaultConstantID = FieldToID(_trigger, defaultConstantID);
                    _trigger = IDToField(_trigger, defaultConstantID, true);
                }


                string[] options = { "Turn Off Trigger", "Turn On Trigger" };
                EditorGUILayout.LabelField("Change State To: ");
                state = EditorGUILayout.Popup(state, options);
            }
            else if(_state == State.CustomAsset)
            {
                parameterID = Action.ChooseParameterGUI
                ("Trigger: ", parameters, parameterID, ParameterType.GameObject);
                if (parameterID >= 0)
                {
                    constantID = 0;
                    _triggerAsset = null;
                }
                else
                {
                    _triggerAsset = (GameObject)EditorGUILayout.ObjectField
                       ("Trigger:", _triggerAsset, typeof(GameObject), true);

                    constantID = FieldToID(_triggerAsset, constantID);
                    _triggerAsset = IDToField(_triggerAsset, constantID, true);
                }

                string[] options = { "Turn Off Trigger", "Turn On Trigger" };
                EditorGUILayout.LabelField("Change State To: ");
                state = EditorGUILayout.Popup(state, options);
            }
            else if(_state == State.DisableAll)
            {
                EditorGUILayout.LabelField("All Trigger Will Disabled in Scene");
            }



            AfterRunningOption();
        }


        public override string SetLabel()
        {
            // (Optional) Return a string used to describe the specific action's job.

            return string.Empty;
        }


#endif

    }

}

Comments

  • I'll need more details on how to reproduce the issue.

    What are your AC and Unity versions? Check Unity's Player and Editor logs to see if they reveal any hints about what's causing the crash.

    If the Object: Send message Action results in the same behaviour, are you able to create a test scene with standard AC Actions that demonstrates the problem?

  • Hello again,

    We discovered that the real problem was not with the Triggers. Since we make the characters prefabricated, it can cause problems in some places. For example; Many animations in the character's animator are trying to load all sprites when trying to load the scene. To avoid this, I create custom animators with the animations used in that scene and re-prefab the Characters. Is there any other solution you can suggest for this situation?

    Another problem was the Post Process settings in Cinemachine. After they fix it, there is no problem in the scene.

    By the way;
    Troop: 2020.1.2f1
    AC: 1.74.5

  • The number of animation clips inside an Animator will have an impact on performance / load times, but this is a product of Unity and not AC in particular.

    One way around this, however, is to remove your cutscene-only animations out of your Animators, and instead use Timelines for your cutscenes.

    See the Manual's "Performance and optimisation" chapter for more advice on improving performance.

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.