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.
-
AuthorPosts
-
November 19, 2022 at 11:23 am #34353
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.
November 19, 2022 at 9:19 pm #34363There 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.
November 20, 2022 at 2:41 am #34368Yes (1) sounds exactly like what I’d need to do.
Thanks a lot you guys are very helpful.
November 27, 2022 at 1:22 pm #34428Hi,
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.
November 30, 2022 at 9:17 am #34439How 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.
December 1, 2022 at 3:06 am #34443Well 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.
December 2, 2022 at 6:48 am #34466The 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?
December 2, 2022 at 12:04 pm #34475Actually 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.
December 2, 2022 at 3:08 pm #34481When 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?
December 2, 2022 at 3:23 pm #34484EntityRig 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.
December 2, 2022 at 5:38 pm #34489Have 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?
December 4, 2022 at 10:29 am #34524Ok 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.
December 4, 2022 at 12:03 pm #34527Glad 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.
-
AuthorPosts
You must be logged in to reply to this topic.