News Forums General Discussion Same BT with different variables

This topic contains 12 replies, has 2 voices, and was last updated by  prime 3 weeks, 5 days ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #34353

    Valon
    Participant

    Hi,

    Is it possible to have the same BT but with different variables and waypoints in them.

    Basically I have a bunch of soldiers and it works fine but now I want them to have each their own path, etc.. I would like to know if I can do it without just copy/pasting the BT (I would end up with like 30 and it might get annoying).

    Just like “do the same thing as this guy but in this path instead”.

    Thanks.

    • This topic was modified 1 month, 1 week ago by  Valon.
    #34363

    prime
    Keymaster

    There are a couple of ways to do this:

    1) Set the name of the waypoints you want to use into a variable. Then make sure the Waypoint node references the variable rather than the name of the Waypoints directly.

    2) You could take just the part of the tree that follows the waypoints and swap it for a Behavior Tree Binding. Then create a number of sub trees based on the waypoints part. In each AI, you would attach the appropriate sub behavior tree into the binding (this appears in the Mind element of the AI.)

    I suspect (1) is what you want. It’s easy enough to set up variables for your AI that hold the value of the Waypoint route you want to use. This can be done via code or by pre-setting it into AI memory.

    (2) can be useful if you actually use slightly different behavior in each case and you want to customize different behavior trees.

    #34368

    Valon
    Participant

    Yes (1) sounds exactly like what I’d need to do.

    Thanks a lot you guys are very helpful.

    #34428

    Valon
    Participant

    Hi,

    I have one more question, this time it’s about Entities but I figured I will not post a new one for this to not flood this forum.

    Basically I have this on my code that works fine :

    myRig = myHero.GetComponentInChildren<EntityRig>();
    myRig.Entity.IsActive = false;

    This is just some lines, not the full code, the second one is actually in an “if”.

    But somehow my Entity is NOT disabled. I debugged it and it does enter the “if” then it does myRig.Entity.IsActive = false; just fine according to the script and then nothing happens in game. My Entity and Aspect are still on and I am still getting detected by the bad guys.
    I only have one Entity and one Aspect (called aHero) on my Hero so I don’t think this can be messed up.

    Maybe something has changed since the last update? I dl it a not that long ago and I clearly remember this was working with another of my “hide” object (I have bushes and closets). Now neither of them work anymore and I didn’t touch the old script.

    Thank you.

    #34439

    prime
    Keymaster

    How are you determining that your entity is still active? Setting IsActive = false will not change the enabled/disabled status of the component in the Unity hierarchy.

    Also, setting the Entity to inactive will not remove variables that have already been set. In other words, if an AI has already detected the Entity, it won’t suddenly forget the detection when you set the Entity to inactive.

    I’m currently using this feature in my own code. Seems to be working, so I suspect the issue is something else.

    #34443

    Valon
    Participant

    Well I determine it by going into a hidding spot and I wait for the AI to walk close to it, the script tells that my entity is inactive but when the bad guy comes he sees me like he is supposed to do when my character is in the open which means my Entity is active.

    They definitly don’t see me before I go in. But I did not know that the AI don’t forget the Entity when it’s disabled if he already sees you, so I actually have extra code to enforce that. Maybe this is the part that is not working. But again it was working before so it seems weird to me.

    #34466

    prime
    Keymaster

    The active/inactive checkbox is visible on the Entity from within the Unity Editor/RAIN Editor, so you may want to just double check that it is inactive when you think it should be.

    Outside of that, I’m not sure. Is anything else strange going on - like are you pooling and re-using AI?

    #34475

    Valon
    Participant

    Actually no the checkbox in the inspector isn’t inactive. There is still the thing that the code tells me that it is inactive. I don’t really know what it could be.

    I have a picture here :

    The Entity is named Entity (which I guess is that since I only have one anyways on my hero) and was true. Then I entered the closet and it started to be false. And you can kinda see the guy behind shooting me.

    • This reply was modified 4 weeks ago by  Valon.
    #34481

    prime
    Keymaster

    When is the Entity being set back to active again? You are using the Entity.IsActive property, right? Not the Unity component active property? Can you post a pic of the behavior tree and/or the code that does the set/unset?

    #34484

    Valon
    Participant
    EntityRig myRig;
    public GameObject myHero;
    void Start () {
    		myRig = myHero.GetComponentInChildren<EntityRig>();
    	}
    void Update()
    {
    		if (iHide && !FoVSoldier.Spotted || NightVision.NightVisionOn || iHideBush && !FoVSoldier.Spotted) 
    		{
    			myRig.Entity.IsActive = false;
    		}
    		else
    			myRig.Entity.IsActive = true;
    }

    For the behaviour tree it is basically the one which is used on the tutorial you have on this website (at least the part that handle the detection).

    • This reply was modified 4 weeks ago by  Valon.
    #34489

    prime
    Keymaster

    Have you tried putting debug statements in next to your false/true assignments just to make sure the entity isn’t being set back to active?

    #34524

    Valon
    Participant

    Ok sorry, it took me a while to be able to test that, I did not have any time.

    So for some magical reason, my closet hide that worked before and stopped working is now working again. Only thing I did was upgrading to Unity Pro.

    My bush hide was a problem on another script, not setting a variable right so with some kind of a chain reaction when the soldier was in range my script was putting the entity back to true and then the rain part was seeing me. Got that thank to your suggestion above so thank you.

    #34527

    prime
    Keymaster

    Glad things are working.

    I’ll just mention this for anyone else who may be reading - switching to Unity Pro should have no impact on the functionality of RAIN. I’m guessing that the upgrade just caused something else to get reset or reserialized, which resolved the issue.

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.