News Forums RAIN General Discussion and Troubleshooting Change aspect during runtime

Tagged: , ,

This topic contains 1 reply, has 2 voices, and was last updated by  Sigil 6 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40006

    colosso
    Participant

    Hi

    I’m trying to do the following: A warrior is running across a field towards the enemy tower (to attack it), now in the middle of the field (or some other event) he should turn around and go attack his own tower. I figured i had to change the aspect of the detect nodes in the behavior but somehow I’m unable to access that. Is there a way to change that aspect during run time?

    My approach was something like this:

    AIRig rig = GetComponentInChildren<AIRig>();
            RAIN.Entities.Aspects.RAINAspect aspect = (RAIN.Entities.Aspects.RAINAspect)rig.AI.WorkingMemory.GetItem("aspectVariable");
            aspect.AspectName = "FriendlyTower";

    This does unfortunately not work because the variable stays null all the time.

    The other thing I thought about was to make two behaviorTrees with constrains if the target (a memory variable) is “friendly” or “enemy”. But that seems to me to be an awful lot of work for about 50 characters (everyone with custom behavior).

    So is there a way to access and change this doing run time from the code? Or some other simple way to do this?

    Thank you very much

    • This topic was modified 6 months, 1 week ago by  colosso.
    #40009

    Sigil
    Keymaster

    You can use a memory variable for your aspect name as well (just like your target). Just make sure it is a string.

    So on the memory tab of the AI (second tab) add a variable, make it a string, put in the name of the aspect you want (no quotes here, RAIN already knows it’s a string since you selected it). In your behavior tree, use the variable you made instead of putting in the quoted string (again no quotes, as it is a variable in this case, it just happens to contain a string).

    Does that make sense?

    You can change the aspect you are using at any time by accessing the variable you made in WorkingMemory. It’s a string instead of an aspect though, and you can read or set it to whatever you need at the time:

    AIRig rig = GetComponentInChildren<AIRig>();
    rig.AI.WorkingMemory.SetItem("aspectName", "friendly");
    rig.AI.WorkingMemory.SetItem("aspectName", "enemy");
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.