Forum rules - please read before posting.

Creating ActionRunActionList and parameters via editor script

I have an educational game with over 200 objects that each must be customized with highlights, hotspots and other components. I wrote a custom object editor tool to automate the process that works great with one exception. One of the things that gets created for each custom object is a "Capture" action. I have an ActionList named "CaptureObject" that is parameterized. If I manually reference the ActionList in an interaction I can add the correct parameters into the inspector and the CaptureObject ActionList works. When I try to add the parameters for the CaptureObject ActionList at edit time via my tool the code executes without errors, the interaction is created but none of the parameters show up in the in the ActionList. I checked the parameters in the debugger and they are correct. Any ideas?

Here is the editor code:
                Interaction newCaptureInteraction = SceneManager.AddPrefab( "Logic", "Interaction", true, false, true ).GetComponent<Interaction>( );
                newCaptureInteraction.gameObject.name = AdvGame.UniqueName( hotspotGameObject.name + ": Capture" );
                newCaptureInteraction.useParameters = true;

                // Setup hotspot button
                hotspotScript.useButtons.Add( new Button( ) );
                hotspotScript.useButtons[0].iconID = 0;
                hotspotScript.useButtons[0].isDisabled = false;
                hotspotScript.useButtons[0].playerAction = PlayerAction.DoNothing;
                hotspotScript.useButtons[0].interaction = newCaptureInteraction;

                // Setup "Capture" action
                ActionRunActionList newCaptureActionList = new ActionRunActionList( );
                newCaptureActionList.listSource = ActionRunActionList.ListSource.AssetFile;

                // Setup the action list by first loading the asset
                ActionListAsset actionListAsset = ( ActionListAsset ) Resources.Load( "CaptureObject" ) as ActionListAsset;

                actionListAsset.parameters[0].SetValue( newBaseObject );
                actionListAsset.parameters[1].SetValue( newInventoryItem.id );
                actionListAsset.parameters[2].SetValue( hotspotScript );

                newCaptureActionList.invActionList = actionListAsset;
                newCaptureInteraction.actions.Add( newCaptureActionList );

Comments

  • If you're running this for each object, the issue will be that you're overwriting the parameters for the ActionList asset each time - meaning they'll only be the values that were set the last time this code is run.


    The ActionListAsset should only be referenced in the code so far as assigning the "listSource" goes.

    You should instead set the values within the ActionRunActionList Action:

    newCaptureActionList.setParameters = true;
    newCaptureActionList.localParameters[0].SetValue (newBaseObjects);
    // etc


    This will cause the parameter values to be transferred to the asset file when the Action itself is run - not when the code is.
  • Hi Chris,

    Thank you for your quick reply. You have the best support of any of the tools/assets I have purchased from the asset store!

    I understand why this is not working based on your explanation. I tried making the changes you suggested and I was getting an error in the debugger when setting the first parameter. Here's the code that I had to add to make this work, in case anyone else wants to do the same kind of thing:

                    // Setup "Capture" action
                    ActionRunActionList newCaptureActionList = new ActionRunActionList( );
                    newCaptureActionList.listSource = ActionRunActionList.ListSource.AssetFile;
                    newCaptureActionList.setParameters = true;
                    newCaptureActionList.localParameters.Add( new ActionParameter( ActionListEditor.GetParameterIDArray( newCaptureActionList.localParameters ) ) );
                    newCaptureActionList.localParameters.Add( new ActionParameter( ActionListEditor.GetParameterIDArray( newCaptureActionList.localParameters ) ) );
                    newCaptureActionList.localParameters.Add( new ActionParameter( ActionListEditor.GetParameterIDArray( newCaptureActionList.localParameters ) ) );

                    newCaptureActionList.localParameters[0].SetValue( newBaseObject );
                    newCaptureActionList.localParameters[1].SetValue( newInventoryItem.id );
                    newCaptureActionList.localParameters[2].SetValue( hotspotGameObject );

    This works great now and will save me three extra steps for each of the over 200 objects I have in my game. You have come to the rescue again Chris!

    Thankagain,

    Steve
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.