Forum rules - please read before posting.

Reusable ActionLists

Hi guys!
I'm trying to create ActionLists for reusable objects in my game such as doors, collectable items, buttons etc. Unfortunately simple ActionLists can't be stored in a prefab. ActionList Assets seem to be an appropriate tool, but I can't find a way to pass it a parameter from my hotspot (wich is in a prefab). I didn't try to do it with a custom script yet, because I think there should be a way to do it using inbuilt Adventure Creator tools. Am I right?
And how do you, guys, call reusable ActionList Assets in your games?

Comments

  • Scene-based Actions can't exist as prefabs, which is indeed why the ActionList Asset feature exists.  Parameters can be created for them (and for scene-based lists too) from the top of their Inspector (see this tutorial).

    More info can also be found in Section 5.13 of the Manual.  To pass a Hotspot to an asset as a parameter, you'll want to define a GameObject parameter.
  • edited August 2016
    Sorry, Chris, but I still don't get it. I use AC v1.53 and I don't see a way to pass parameters to an ActionList Asset directly from a Hotspot. I can do it from another ActionList, but this ActionList can't be attached to a prefab, so I'd still have to do it for each item in scene manually (which is not very cool). Is there a way to store and pass those references entirely in a prefab?

    image
  • edited August 2016
    ummm... when you use parameterized Actionlists you have to think of them as Utility Scripts, not as the final end scripts. Now that you have that parameterized Action list, make another Actionlist which uses the ActionList: Run action, if you use that, and you select your parameterized actionlist, it will give you the fields to fill the parameters you created. But, action list assets are best for complex processes. Seeing how you are just using one action to call a method in a script, your only gain will be reducing the number of fields you need to fill up to just one, the game object. Also, I don't really think there's an equivalent to "this" or "gameObject" in AC's object send message (or is there?). 

    If what you wanted was to create one single action list to put in all of your objects without doing any additional steps, your best bet would be to create a custom action which, inside the public override run() function calls:

    this.GetComponent<yourScript>().OpenDoor()

    return 0;

    Then slap that action into an action list asset. That may or may not work (depending if the hotspot component is or not in the object you want to affect), you will probably need to slap a hotspot component manually, directly on the object you want to affect (that will also allow you to prefab the hotspot). Anyway, I personally use raycast to automatically open doors, or to do it when a specific keypress is detected within the raycast's range, but you could give that option a try.
  • edited August 2016
    As @Alverik states, parameters are primarily intended to be set with the ActionList: Run Action, which allows you to set the values of each parameter the new ActionList holds before it is run.  The current "correct" way to do it would be to have one Interaction per Hotspot instance (so that it knows which Hotspot it's used for), each of which contains a single such Action that calls the parameterised, re-usable, ActionList.

    However, there are some other cases when parameters are set in other circumstances - such as the Trigger, which allows you to set the object which collides with it as its own parameter.

    While calling an ActionList that uses parameters directly from a Hotspot doesn't allow you to set a parameter in the same way, that could be a worthwhile addition.  Would something in the form of a "Set Hotspot as GameObject parameter?" checkbox be suitable for your needs?
  • edited August 2016
    @Alverik the screenshot is not full. I also have a second action, that plays animation on a second GameObject parameter. Anyway, it's more about having handy tools for future development, than completing a specific task. I want to create reusable action sequences that can be easily applied to my newly instantiated game objects.
    @ChrisIceBox I'll try to write my own Parameter Keeper script, that would store a list of parameters and apply them to an ActionList on start. But if it's not possible, I'd like to use "Set Hotspot as GameObject parameter?" checkbox.
  • Noted, I'll look into it.
  • Yeah, I'm not sure it's what you have in mind, but a "send to self" would really make a difference too. Specially when you have many objects sharing the same script and you want the action list asset to be useful for all of them without specifying the game object.
  • Could you give an example, @Alverik?
  • edited August 2016
    um, well, like in the door script example as he had mentioned. Imagine all your doors use the same script, same method. If you had the option to send the message to itself (i.e.: gameobject hotspot script is attached to), you could just go ahead and 1. put a hotspot script on all your doors. 2. Make a single actionlist asset sending the "opendoor" message to itself then put that action list in the actionlist asset slot in every object you need (all doors in this case). 

    And that would be it. There would be no need to make any more actionlist assets because the message would be sending the message to itself (gameobject hotspot script is attached to), there would also be no need to use any constant id or specify a gameobject this way. The only downside is that you would need to make the user aware that the option only works if you have a script attached to the hotspot itself (or to the game object which has the hotspot script). But anyways, that would simplify situations like that a lot. Specially if you have many repeating objects which share the exact same script, and you want the script's method to trigger using... well, a trigger, heh. 

    This method would also work fine for scripts which only need to be triggered and don't need a specific game object. You could also cover remembering things like states using scene local variables. Though, I see this method working best for repeatable actions (again,things like opening or closing doors/gates, making calculations, activating particles, changing your own custom states of something in your scripts, etc), although as I said, using local variables it should be relatively effortless to remember object states if absolutely necessary. But at the end the biggest gain would be to save you the trouble of having to make dozens of identical action list assets which are simply intended for different game objects.
  • Well, that was always the point behind the introduction of parameters - to create "recyclable ActionLists" that can be called upon to perform common tasks, whether they be just a hide of an object and add to the inventory, or a complex cutscene in which a player opens the door.

    The only difference here is that we're talking of removing the need of an "interim" actionlist - i.e. the one that calls it in the first place.  A parameterised ActionList is normally run with ActionList: Run, whereas the change I'm considering to the Hotspot Inspector would allow a GameObject parameter to be set to the Hotspot automatically.  However, that would only affect that one parameter - if you wanted any others to be set (and most likely you would, for example a Marker for the player to stand, a Camera to cut to) you'll still want to ignore that and use the ActionList: Run Action in a dedicated single-Action Interaction as normal.
  • ummm.. but as I said that would be for small things, allowing you to skip the interim actionlist would make things a lot cleaner in those cases (or exceptions if you must). But anyway, that may be just my taste. In my other working project for PC (first one I ever started...), I initially began by using the parameterized actionlists. Problem is I wanted them to have the feel of Actions, easy to use, plug and play (if needed), reusable in other projects, etc. Also, I don't like cooking spaquetti... doing humongous actionlists feels messy, and I felt it could get confusing later, so I tried to create my action lists in smaller coherent pieces which I then connected to a master Actionlist (simulating an action). But, after making a few of these, I came to realize that it takes longer to search and find actionlist assets once you have a lot of them... something I'm sure others using the normal way also have noticed. I tried using naming conventions to separate the "dependencies" from the "methods", which kinda helped, but still feels messy to me... 

    Anyway, by now I've already gotten a bit better at programming and I've understood custom actions are the way to go for cleanness and easy of use (even if that means some initial hard work, sometimes).
  • edited August 2016
    I end up using solution from this thread (thank you @mm_ash):
    Actions are kept in an ActionListAsset, which is called from an Interaction component saved in a prefab. An additional script Parameters.cs keeps a list of ConstantIDs and assignes them to Interaction.parameters on start. A custom inspector script manages the number of parameters and displays their names. Here is my implementation, maybe it'll help somebody:

    @ChrisIceBox can something like that be implemented in AC? A way to save parameters for an ActionListAsset directly in an Interaction prefab? Or in a Hotspot prefab? To me it sounds like a cool feature, even more powerful than just passing a Hotspot as a parameter.

    image
  • Nice idea @GallopingDino, though without being able to set the values of other parameter types I feel it would be too limiting for an official inclusion.

    If an ActionList makes use of an Asset File for its Actions, and that Asset File contains parameters, would the ability to set "default" parameter values in the ActionList's Inspector be along the same lines as this?
  • @ChrisIceBox hmm... do you mean that default parameters values would be kept inside of an ActionListAsset? But in case of GameObjects those parameters would have to be "global": I don't think this feature would allow us passing "this" GameObject to a parameter, so it won't help in case of door / room / lamp prefabs. Maybe it would be useful in other cases, but it's a question for experienced users, not for a noob like me :)
    Maybe setting values for other parameter types would be possible if we check parameterType value? I didn't try it myself yet.
  • No, more like a local set of default parameters for that Interaction.  So multiple Interactions / scene-based ActionLists that reference the same ActionList Asset file would have their own default parameters.
  • @ChrisIseBox sounds cool, especially if those settings could be saved in a prefab.
  • Yes, I expect that'll be possible.
  • edited August 2016
    I modified my script and now it is able to keep all types of ActionParameters. For that purpose I decided to use List<ActionParameter> instead of List<ConstantID> and added some code to draw correct inspector fields (in that part I used large pieces of code from ActionRunActionList.cs)
    @ChrisIceBox what do you think about that approach? It works for now, but as a not very experienced AC user I might not see some upcoming troubles.
    http://pastebin.com/2FKsgQGW
    http://pastebin.com/cG0gGNd4
    image
  • edited August 2016
    @ChrisIceBox, by the way. While I was studying ActionParameters, I noticed, that ActionParameter.IsIntegerBased() returns false for boolean. Is it a bug?
  • edited August 2016
    Not so much a bug, but returning True for Boolean could result in some added functionality.

    That approach should work fine, but there have been some developments regarding parameters in the latest releases which may be of use:
    • Interactions now accept parameters
    • If a Hotspot refers to an Interaction with a GameObject parameter, that parameter can be set to the Hotspot when run
    • If a scene-based ActionList makes use of an ActionList asset file that uses parameters, default values for those parameters can be set locally if Sync parameter values? is unchecked.
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.