Hello
I'm writing an integration package for Adventure Creator and another asset that includes some custom actions. I haven't really used Adventure Creator before and I'm not familiar with the best practices. Several of the custom actions will return a value. For example an action might return the nearest detected GameObject, or a fractional visibility the object is.
In general would it be more useful for actions to store results in a Variable or in a Parameter. Or in what situations would one be preferred over the other?
I can find only 2 actions in vanilla AdventureCreator that will store a result.
The 'Add/Remove Object' action will store the instantiated GameObject in a parameter.
The 'Record Transform' will store the result in a variable.
It looks like they both have pros or cons but I'm really at a loss which one is preferred in general. I think that storing to parameters might be more useful, but I just want to make sure.
Any advice or suggestions would be appreciated.
Thanks!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Welcome to the community, @adam4lexander.
I imagine it comes down to the way in which you'd want to then access that returned value.
When dealing with parameters, its "safest" to limit their usage to within the ActionList they're a part of, while that ActionList is running. If you want to access the returned value elsewhere, I'd put variables as being the better choice.
Thanks for the response.
The integration package is meant to be general purpose, so the returned values may sometimes only be used in the running ActionList, and other times it will be accessed elsewhere and will need to be in a variable. Ideally the user of the integration package can use either pattern depending on their needs.
I thought a parameter might be preferred, so you don't need to create a new variable when the returned value will only be used in the running ActionList. I believe the user still has the option of creating a variable and saving the parameter to the variable if they need to.
On the other hand if I return the value in a variable then the user will always need to create a variable of some kind to store it in. Even if the value is only used in the running ActionList.
Would you recommend variables for general purpose actions designed for both use cases?
Yes, that's true - as is the reverse. Both parameters and variables can be converted to one another, using the ActionList: Set parameter and Variable: Set Actions.
If you're happy with the caveat of an additional Action being necessary in such cases, parameters would then likely be the better choice - since you can then keep all the logic necessary for the Action to run limited within the ActionList itself.
Thanks for the help.
I managed to find a way to support both in a single action. The user can choose from a dropdown if the result should be stored in a variable or in a parameter.
There's a lot of code needed to handle either case but its possible to abstract 95% of it away into a utility class that manages both storage options. With that its pretty straightforward to implement storage options in an Action with only a few lines of code.