Forum rules - please read before posting.

How to make one ActionList for each NPC

edited December 2022 in Technical Q&A

Hi guys I have a problem with an ActionList I'm creating for the dialogue of the NPCs. Basically inside this ActionList there are as many ActionVarCheck as the states of the NPCs. Foreach ActionVarCheck there is a component variable taken from the NPC that checks Its value and then continues to the next actions. The problem is that if I wanted to make a single ActionList, It wouldn't be possible because the component variable must be unique for each NPC. To resolve this I should duplicate the entire ActionList foreach NPC and then replace the variable on each ActionList. Is there any method to do this without duplicate the ActionList?

Comments

  • Welcome to the community, @Pietrofonix.

    Actions have a "parameters" feature, that can be used to help recycle ActionLists by modifying certain fields each time they're run. A tutorial on their usage can be found here.

    I'd need to see the specific Actions and logic you're running, but it may be that you can use parameters to recycle such logic - both variables can be parameterised, as well as strings such as speech text.

    If you can rely on PopUp variables (if appropriate) it's also possible to rely on the "Variable: PopUp switch" Action to run multiple different outcomes based on its value, rather than having to check each with a separate Action.

    If you'd like to share some screenshots of details of exactly what kind of logic you're running, I can take a look to see if I can offer more specific advice.

  • edited December 2022

    Hi Chris thank you for the answer, anyway for the replacement of the variables I resolved via code by accessing the Actions properties, but I will take a look at the parameters. For the ActionList instead I would like to keep just one for all NPCs if possible. For example, https://mega.nz/file/FJtxDIAA#aTVVbzd1d9ZJsjpVrzqTNOjVKttM__KshEGaJt5QF_4 this is a branch of my behavior tree (inside each NPC) where, inside the BDPlayDialogue node, I just run the ActionList that I drag and drop in It with .Interact(). The problem is that If each NPC uses this ActionList, It would only play dialogue for one single NPC, so in this case I should duplicate the ActionList for each NPC and assign it to each BDPlayDialogue node. Is there a way to use only one ActionList for everyone?

  • edited December 2022

    ActionList parameters are designed to help reduce the number of ActionLists in your game, though mileage will depend on how much you want to alter an ActionList when its run.

    The Dialogue: Play speech Action can have both its character and speech fields overridden - through GameObject and String parameters respectively. If you're just looking to change which character says what, then it should be possible to condense things into one.

    Parameter values are set at the time the ActionLists are run - so you'll first need to move your Actions to an ActionList asset file (if not already), and then attach the ActionList starter component to your NPCs. Once they're set up to reference the ActionList asset, you'll be able to configure the values for any parameter that asset has defined.

    To run the ActionList with the correct parameter values, run the "ActionList starter" component's RunActionList function - as opposed to the ActionList's Interact function. This will set the parameter values and then run the asset.

    I'd still recommend following the above tutorial first, however. It'll help to work by simple example before tackling your more complex case.

  • edited December 2022

    Hi Chris, thank you for the answer and sorry for the delay in replying. I've tried as you said and it seems to work. Basically I didn't use the ActionList parameters but I put the ActionList Starter component in each NPC and then, inside the script of the BDPlayDialogue node of the behavior tree, I've accessed the PlayDialogue actionlist (this time from asset) with this code:

            foreach (ActionListAsset acListAsset in m_actionListStarter.GetReferencedActionListAssets())
            {
                foreach (AC.Action ac in acListAsset.actions)
                {
                    var actionSpeech = ac as ActionSpeech;
                    var actionVarCheck = ac as ActionVarCheck;
    
                    if (actionSpeech && !ActionsSpeechList.Contains(actionSpeech))
                    {
                        ActionsSpeechList.Add(actionSpeech);
                    }
    
                    if (actionVarCheck && !ActionsVarCheckList.Contains(actionVarCheck))
                    {
                        ActionsVarCheckList.Add(actionVarCheck);
                    }
                }
            }
    
            for (int i = 0; i < ActionsSpeechList.Count; i++)
            {
                ActionsSpeechList[i].speaker = Npc;
            }
    
            for (int i = 0; i < ActionsVarCheckList.Count; i++)
            {
                ActionsVarCheckList[i].location = VariableLocation.Component;
                ActionsVarCheckList[i].variables = Owner.GetComponent<AC.Variables>();
    
                if (ActionsVarCheckList[i].comment != "IsInvestigateAudioAction")
                {          
                    ActionsVarCheckList[i].variableID = Owner.GetComponent<AC.Variables>().GetVariable("NPCState").id;
                }
                else
                {
                    ActionsVarCheckList[i].variableID = Owner.GetComponent<AC.Variables>().GetVariable("IsInvestigateAudio").id;
                }
            }
    

    So with this I can modify in runtime the fields of the actions inside the ActionList

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.