Update loop in Actions?

  • September 1, 2017 at 20:44 #21838
    edwon
    Participant

    Is there no update loop in Actions? What’s the best way to deal with actions that happen over time?

    September 4, 2017 at 10:08 #21845
    Rami
    Keymaster

    Hi Edwon,

    Thanks for your post.

    No, there is no update loop in a traditional sense within an action.

    Instead, you should take advantage of the fact that the AI itself is executed on an interval. Thus, if you need a long running action, you handle this in the AI by diverting the decision making of any given AI execution to whatever action is relevant.

    Thus, in a way, you can consider an action’s “Execute” method as an “update loop”, assuming that it is the only action and it is called often (enough).

    September 4, 2017 at 10:23 #21847
    edwon
    Participant

    Ah ok I see what your saying in the sense that execute is called over and over on the same action when that action continues to have the highest score.

    So a tricky thing in my case is synchronizing a pre-existing procedural animation system I’ve created with several of its own sub-coroutines, mechanim animators, path finding, etc… and syncing it all with apex utility Ai is going to be tricky.

    I’m writing a very simple version of the game right now just to test with your plugin, and I currently represent all that animation complexity with a simple enum called state, and even with it being that simple i had to hardcore some logic in (by setting one score to 1000 to ensure it stayed there during animation for example) to make sure it stayed in sync with the utility ai.

    Do you have any suggestion for the best way to sync between complex animations and the utility ai? One idea I had was to have my animation system listen for changes to a selector or qualifier and react accordingly. I’m open ears to your ideas!

    September 4, 2017 at 10:47 #21849
    Rami
    Keymaster

    It sounds to me a bit like you could possibly be overcomplicating. Of course, I don’t know exactly how complex or what kind of structure your animations are set up in, so what I say may not be correct for your case.

    In general, using an enum to control animations is quite common (especially in Unity due to Mecanim). I would consider having an action for setting the enum. Remember you can expose fields to the inspector using the [ApexSerialization] attribute. Thus you can have 1 scorer for testing whether the state is what you desire, and 1 action for incrementing or decrementing the state.

    I have a hard time seeing why you would need to listen to the AI’s execution. You control the AI. So if you need something to happen every time an action is chosen, then you do what you need to do in all your actions and subsequently store the result in the Context so that the next evaluation can continue from that point on.

    • This reply was modified 3 months, 1 week ago by Rami.
    September 6, 2017 at 19:16 #21861
    edwon
    Participant

    Ok cool, one hitch though, so in my real game (not just the prototype), my animations are controlled by a bunch of different methods in my AnimationControl class, so for example I can call FlyTo(Transform target) or WaveArm(float speed)

    My issue right now is that I want to create an Apex Utility AI custom Action that called AnimationAction that can call any of these methods.

    I was thinking one way to do that would be to use reflection to read the class, auto-generate an enum to choose which animation, and then automatically fill the AnimationAction inspector with the parameters. The only problem is I don’t know how to do that last part. Is there a way to write a custom editor for Actions?

    September 6, 2017 at 21:18 #21863
    edwon
    Participant

    Ok I came up with a solution that generates one action per method that I’ve tagged with a custom attribute. It uses reflection and works well. Only issue now is that I’d like to be able to put my actions in categories of some kind, so that there’s not too many options in the actions pop up in the utility ui. Is this possible?

    September 7, 2017 at 11:11 #21869
    Rami
    Keymaster

    All actions will show up in the pop-up. It is up to you to come up with naming conventions or other measures that help you select the right one.

    September 7, 2017 at 20:50 #21872
    edwon
    Participant

    Ok, I did that already, for example all my animation actions start with Anim, but still, it would just be nice if , similar to the “Add Component” menu in Unity, if the actions had categories and a branching menu. Consider it a feature request.

    Thank you for your help so far. I appreciate the support.

    September 8, 2017 at 10:03 #21892
    Rami
    Keymaster

    I agree that it would be a nice feature. It has been logged in our backlog, but I cannot say when or if it will be implemented.

    • This reply was modified 3 months, 1 week ago by Rami.

You must be logged in to reply to this topic.