Forum rules - please read before posting.

Actions on an ActionList being called out of order?

edited March 19 in Technical Q&A

Hello!

I have this ActionList, and the last Action is an Object : Call Event

Basically the ActionList checks if an ActionList GameObject property is empty, if it is instantiate a GameObject and set the Property to it, otherwise, delete the GameObject, instantiate a new one and set the parameter.

Once that's done set the parent of the newly created GameObject.

Finally call the event.

Here's the code of the Event

    public void UpdateHints(GameObject hotspot)
    {
        int index = hotspot.GetComponent<HotspotKey>().index;
        GameObject hint = null;
        foreach (Transform t in hotspot.transform)
        {
            if (t.CompareTag("Hint"))
            {
                hint =  t.gameObject;
                break;
            }
        }
        if (hint != null) 
        {
            hints[index] = hint;
        }
    }

The first time I run the ActionList it works fine, however, the second time onwards the Event seems to be being executed before the other actions finished executing, that is because when adding a breakpoint to the beginning of the Event code I can see that that old GameObject is still instantiated and the new one has not been instantiated yet.

However if I add breakpoints to both the Event code and the Action before the event is called, it seems to work fine.

I'm not sure what could be the problem here... Any ideas?

Thanks!

Comments

  • Welcome to the community, @BokeTsukkomi.

    Admittedly I'm looking at the ActionList out of context, but I'm not sure I follow the lists logic. The first Action runs a null-check on "HotspotPosition", but its then "CurrentHint" that gets updated, and parented to HotspotPosition even if null.

    In case your intent is to check the object exists before removing it: the Object: Add or remove Action will simply do nothing if you attempt to remove a null object - the Action flow will still continue.

    Rather than using a breakpoint, try attaching comments to each Action: select all Actions, right-click and choose Comment selected. Enter in some text for each, and then set the Settings Manager's Action comment logging field (at the bottom) to Always. That should help determine which order each Action is being run in.

  • Thanks @ChrisIceBox

    After posting I've removed the first action (as you said it's irrelevant :)) and I did some changes

    This is the source code of the Event that is called

     public void UpdateHints(GameObject hotspot)
     {
            //Doing a bunch of stuff that's irrelevant
            Debug.Log("Hints updated!");
     }
    

    And the order that the comments are printed is

    Hints Updated!
    Call Event
    ActionList: Run
    

    Now here's the thing: If in the first ActionList I add an Engine: Wait of 0.1 seconds before the ActionList: Run action, everything works fine.

  • An Action's comment is actually called after it's run, which admittedly is confusing.

    You can amend this by opening AC's ActionList.cs script, and moving line 474:

    PrintActionComment (action);
    

    up to around lint 465 (i.e. above the action.Run() call.

    I'll make the same change to the next release.

    Having made the changes to the Actions, what is the actual behaviour now - comments aside? Is the addition of the Engine: Wait Action causing the logic to behave as intended?

  • An Action's comment is actually called after it's run, which admittedly is confusing.

    You can amend this by opening AC's ActionList.cs script, and moving line 474:

    Gotcha! I'll fix this

    Having made the changes to the Actions, what is the actual behaviour now - comments aside? Is the addition of the Engine: Wait Action causing the logic to behave as intended?

    Let me give some more details on what I am trying to achieve. So my sequence of actions are

    • Remove an existing GameObject (if any)
    • Instantiate a new GameObject from an Inventory Item's Linked Prefab
    • Reparent the newly instantiated GameObject
    • Call an Unity Event via Object: Call Event
    • Within the event I search the GameObjects of my scene looking for the newly created GameObject and add it to a list.

    Without any breakpoints or waits this logic works the first time it's called for a given Hotspot, but it doesn't work on the second time because the new GameObject still does not exist when the Event tries to manipulate it.

    However, if I add an Engine: Wait after the reparenting and before calling the event, or if I add a breakpoint to the Set Parent Action, the Event works fine all the time.

    I'll check my code again to see if it's something on my side (most likely :)), but because it works if I add an Engine: Wait is what makes everyting seems really odd...

  • It's hard to glean exactly why, as the logic flow / custom scripting is specific to your project - but it sounds like it needs a frame to update things.

    Try using a wait time of -1. A negative value causes it to wait exactly one frame, regardless of frame-rate.

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.