Forum rules - please read before posting.

Copy GameObject parameter from one ActionList to another

Hi,

One of my ActionLists is starting another one and I need to copy a GameObject parameter from the first to the second. The thing is, the second ActionList is defined at run time through custom Action, so it will differ depending on what's happening in the game.

I was thinking of adding another custom Action at the start of the ActionList2, which would do something like this:
ActionParameter myParameter;
and then
myParameter.SetValue(AC.GlobalVariables.GetIntegerValue(14));
Global Variable being a Constant ID of the GameObject, but I can't figure out how to set the myParameter to the current ActionList's parameters.

ActionList:Set Parameter allows you to copy parameters, but it seems like it can do so only from within the same ActionList. It also allows you to copy from Global Variable, but that doesn't include GameObjects.

Is there a way I can pass GameObject parameter from ActionList1 to ActionList2 at run time?

Comments

  • Are the ActionLists assets or scene-based?

    If scene-based, you could simply read the parameters of ActionList1 and transfer them to ActionList2 - but with assets you have to be careful to read the "instance" of ActionList1 and not the asset itself (see my comments in your other thread).

    To modify the parameters of an ActionList instance from within an Action, you can add an override to the AssignValues method in your Action. This method includes the parameters as a function parameter:

    override public void AssignValues (List<ActionParameter> parameters)
    {
        parameters[0] = myParameter;
    }
    
  • edited December 2018

    The ActionLists are assets, not scene-based.

    I've played around with this, but still can't get it to work as intended. I tested it with:

    character = GameObject.Find("Character1(Clone)");
    parameters[0].SetValue(character);

    And it works, but it's very specific. It's probably basic scripting problem, but is there a way to reference character by his Constant ID?

    The custom Action that runs ActionList2 takes a note of current character's ID (from ActionList1 parameter) but I just can't figure out a way to later use it to find that character by his ID in ActionList2.

  • Is there a way to reference character by his Constant ID?

    Yes, the returnComponent function can be used for this:

    Char myCharacter = Serializer.returnComponent <Char> (myConstantID);
    
  • Thank you! This should do the trick!

  • edited February 2019

    Hi, going back to this, I ran into a problem with passing the parameters between ActionLists.

    My ActionList1 gets a parameter from the character that you're talking to from this thread. ActionList1 then triggers ActionList2 which starts with a custom action that assigns the parameter by character's ID from the tips above in this thread.

    My custom action has an override function to AssignValues, like this:

    override public void AssignValues(List<ActionParameter> parameters)
            {
                charToPass = AC.GlobalVariables.GetIntegerValue(14);
                Char character = Serializer.returnComponent<Char>(charToPass);
    
                parameters[0].SetValue(character.gameObject);
            }
    

    This works well, but I realised that the parameter gets "broken" after a prefab Start Conversation action with Override options? ticked on. Adding ActionList: Set parameter after the Conversation Action helps solve this, but that's adding quite a bit of work, specially that some dialogues have a lot of Conversation Actions.

    I've tried manipulating the AssignValues code, trying to replicate what the code from the other thread does, but I still can't get it to work properly.

    I think what I'm after, is to find a way to assign the parameter to ActionList instance, but I can't find a way to do this. Unless I totally misunderstood the whole thing and the problem is something completely different?

  • The code in your AssignValues function is updating the paramters of the instance of the ActionList asset - not the ActionList asset itself. When AC runs an ActionList asset, it actually spawns a RuntimeActionList class, and copies the asset's Actions only it so that they are present in the scene.

    What you'll need to do is also update the original asset. A reference to ActionListAsset can be gotten either by exposing another field in ShowGUI, or by creating an override for Action's AssignParentList function, which provides the ActionList as a parameter. You can case this to RuntimeActionList to extract the asset, i.e.:

    private ActionListAsset myAsset;
    override public void AssignParentList (ActionList actionList)
    {
        RuntimeActionList runtimeActionList = actionList as RuntimeActionList;
        if (runtimeActionList != null)
        {
            myAsset = runtimeActionList.assetSource;
        }
    }
    

    With myAsset assigned, you can then update its own parameters in the same way.

  • Thank you so much, this is super helpful! This works really well now and it's going to be very useful when creating longer ActionLists!

  • Hi,

    I have ran into a small problem with this code recently, after updating AC from 1.65.2 to 1.67.5

    So what I'm trying to do is to click on the character which runs ActionList Asset which has a custom Action that runs another ActionList Asset and I'm trying to pass the parameter between the two.

    The second ActionList Asset (where I'm passing the parameter to) has a custom Action with code from above in this thread.

    I also have an Object in the scene with code from this thread: here.
    The two worked fine before updating AC, but now I'm getting a Unity Warning: Cannot set the value of parameter 0 ('Character') as SoldierSprite has no Constant ID component.

    The interesting thing is that this still works as expected in game, I just get the warning (I'm not really sure how big of an issue this is).

    In this case the "SoldierSprite" refers to the child object of an NPC. Now, adding the Constant ID to the child fixes this warning, but the Character is a prefab and so the root of NPC already has Constant ID.

    Is there something that could cause this that I'm not aware of, and / or simply adding the Constant ID is fine? (but then every NPC in the game would have Constant ID on the root object and on the sprite child).

    I hope this makes sense. I'm not sure if I'm getting worried about nothing here (Unity warning), if there's a way to fix this in some other way, or simply adding Constant ID's to all child objects in NPC's is fine.

  • It's an AC warning, not a Unity one. Typically it needs to be heeded, but not necessarily so if you're using custom scripting to set/pass your parameters.

    If the object is being assigned correctly in-game, it generally would only need a CID value if some reference to it needed saving at runtime. Otherwise, it should be safe to ignore - CID warnings assume the worst sometimes and can occasionally show when it's OK.

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.