Hello !
I'm asking for some help today because I got a little problem.
I'm trying to create actions from script, and I want to run an ActionList that is in my Assets folder.
I found a similar topic, but it didn't help me..
ActionRunActionList playDialogue = ScriptableObject.CreateInstance("ActionRunActionList") as ActionRunActionList;
playDialogue.listSource = ActionRunActionList.ListSource.AssetFile;
playDialogue.setParameters = true;
playDialogue.invActionList = Resources.Load("ActionLists/PlayDialogueAL", typeof(ActionListAsset)) as ActionListAsset;
playDialogue.localParameters[0].SetValue(1);
But it does not work, because the list localParameters is empty.
I tried to fill it but I don't know how to get the IDs of the parameters.
playDialogue.localParameters.Add(new ActionParameter(1));
works but I get warnings so.. that's not a good way
Did I do something wrong ? If anybody knows a solution, I would appreciate to know it
Thank you !
Comments
A parameter's ID number is shown to the left of it's label when defined in the ActionList properties.
If you're going to the trouble of running a parameterised ActionList asset through code, then it's probably best to just skip the ActionRunActionList instance and just set the parameters directly and then run it. That's essentially how ActionRunActionList works:
ActionListAsset playDialogueAL = Resources.Load ("ActionLists/PlayDialogueAL", typeof (ActionListAsset)) as ActionListAsset;
playDialogueAL.parameters[0].SetValue (1);
playDialogueAL.Interact ();
We will, don't worry.
The error message displays if the number of parameters present in the asset do not match those listed in the ActionList: Run Action.
This normally occurs if you add more parameters to the asset after setting up the Action.
AC checks for this match at runtime and when viewing the Action's UI, and resizes the Action's list of parameters accordingly.
How many parameters does the asset have? You will need to add the same number of parameters to the ActionRunActionList.
If you're not viewing the default UI, you could try invoking it manually - to force the check - by running the Action's ShowGUI method. Otherwise, you could look copying code from the the private SyncLists method.
http://pasteall.org/846186/csharp
Attach it to a Cutscene in your scene that has no Actions except for the default. Make a new ActionList asset file that has a single String parameter, and then pass that to speech text using Dialogue: Play speech.
(You can insert a parameter into a speech with [param:0])
Have the script above refer to both the Cutscene and the asset file in the Inspector fields, and then run the scene. The Cutscene should change to the ActionList: Run Action, and then set the asset's parameter correctly when Run now is clicked.
The warnings disappeared when I set all the parameters.
I used this code :
I probably could enter IDs like 1, 2, 3 ...
But it's perfectly working for now
thanks again !