News › Forums › RAIN › General Discussion and Troubleshooting › hello! is this thing on
This topic contains 12 replies, has 3 voices, and was last updated by prime 4 weeks, 1 day ago.
-
AuthorPosts
-
January 19, 2023 at 10:31 am #35127
Well my 5th post now still no replies to any post iv written so there’s that. I just want to know how to unassign the ai from a character during runtime and assign ai to a charactger during runtime
January 20, 2023 at 12:40 pm #35138I am EXTREMELY new to RAIN and attempting to do the same thing. My thought although it maybe wrong is to have a prefab that is just the game object with the pre-frab rig on it (the thing that create ai creates on a game object as a child) then at run-time instantiate it and add it as a child. Then set the body as the parent you parented it to…
I could be wrong.
January 20, 2023 at 12:45 pm #35139BTW I am not all the way done but it is working.. you have to reattach a few things back to the main body I have found like mount points etc… we shall see if it works…
January 20, 2023 at 12:52 pm #35140Here is a snippet that does it for me….
GameObject goBase = Instantiate (Resources.Load("Library/AI/AITest") ) as GameObject; if (goBase != null) { goBase.transform.parent = newAvatar.transform; AIRig aiRigComp = goBase.GetComponentInChildren<AIRig>(); if(aiRigComp != null) { aiRigComp.AI.Body = newAvatar; IList<RAIN.Perception.Sensors.RAINSensor> sensesCopyFrom = aiRigComp.AI.Senses.Sensors; for(int i=0;i<sensesCopyFrom.Count;++i) { if(sensesCopyFrom[i].MountPoint != null) { sensesCopyFrom[i].MountPoint = newAvatar.transform; } else { Debug.Log("goAIGuide is null in AIMGR"); } } } else { Debug.Log("aiRigComp == null in AIMGR"); } } else { Debug.Log("goBase == null in AIMGR"); }
- This reply was modified 1 month ago by RyanMitchellGames.
January 20, 2023 at 10:56 pm #35149Brilliant man thx I will try it out some time.(The code used for rain really hurts my brain though) I decided to try write my own ai for the bits I was going to use rain for so If it sucks I at least can try your approach. I was also thinking along the lines of swapping out the ai rig char with another rig sans the Ai not a clue how I was going to go about it prolly onenable or something along those lines new to coding so who knows where I would have ended up lol.
January 21, 2023 at 9:57 am #35161@RyanMitchellGames - The code you posted is for copying an AI from one body to another. Yes, sensor mount points do need to be updated (glad you posted that).
Here is an alternative if you are simply adding new AI:
- Create a prefab of the AI. Instantiate the prefab, attach it to the avatar, set the body, then call AIAwake and AIStart on the rig. If your sensor mount points can be made relative to the prefab, then you don’t have to do anything more.@tawdry - and to unassign it, simply destroy the AIRig on the avatar.
January 21, 2023 at 10:50 am #35165Hi Prime. Thx for chipping in I put the replies from this post into google translate and it assures me you guys are speaking english lol .
1 Create a prefab of the AI.// I know what a prefab and a AI is but how do i create a prefab of an Ai?Empty game object with the replacement Ai attached?
2 Instantiate the prefab, attach it to the avatar.// Attach the empty GO ai as a child of the avatar?
3 set the body not sure what to do with this line.
4 then call AIAwake and AIStart on the rig.// say what? how do i call these in unity script?
5 If your sensor mount points can be made relative to the prefab, then you don’t have to do anything more // Ok so something to do with e=mc2 and solving Pi?
6 and to unassign it, simply destroy the AIRig on the avatar. // Don’t want to destroy the Ai just cause it to lose conciousness for a bit . For example i have a chap who works during the week and parties on the weekend. So his behaviour tree will be vastly different from week to weekend but he will need to return to week behaviour after letting his hair down .January 22, 2023 at 7:53 am #351991) When you rig up an AI in RAIN, by default it creates an AI child game object and adds the AIRig to that. You can make a prefab out of just that AI child object.
2) Attach the AI child object you made into a prefab
3) Grab the AIRig off your new object:AIRig tRig = tNewlyInstantiatedObject.GetComponentInChildren<AIRig>(); tRig.AI.Body = yourAvatarObject;
4)
tRig.AIAwake(); tRig.AIStart();
5) By default, the mount point of a Sensor is the parent the AI was originally rigged on. So in most cases you WILL need to grab your sensors and reset their mount point to the new AI Body.
6) If you are simply switching the Behavior Tree, then all the rest of this is overkill. You can swap the behavior tree on the fly with a single call. On the other hand, if you are simply trying to move the AI Memory between two different setups, that is simple too and doesn’t require copying the AI. Before I go into more detail, what exactly are you trying to accomplish? There may be a far easier solution.January 22, 2023 at 4:35 pm #35222Hey Prime
For example i have a chap who works during the week and parties on the weekend. So his behaviour tree will be vastly different from week to weekend but he will need to return to week behaviour after letting his hair down .
Yea just want to swap the Ai sometimes . Using my example above put in a weektime behavior Ai then swap to a weekend Ai then back again etc.
Also if I enter a combat situation want to disable the Ai so i can do the combat in C# then re enable brain.
Basically want rain to run all the everyday functions but do the specialized actions in C#January 22, 2023 at 5:19 pm #35223There’s a SetBehavior call on the BasicMind that let’s you swap out just the behavior tree. This works based on a BTAsset, which you can load through Resources.LoadAssetAtPath(). (You may need to move the BTAssets into a Resource folder)
To disable an AI temporarily, just do
AIRig tRig = gameObject.GetComponentInChildren<AIRig>(); tRig.AI.IsActive = false;
January 23, 2023 at 3:24 pm #35250Hey Prime
Thx that works for the disable curious why the use of t(t rig) so much? favorite letter or something else?January 26, 2023 at 9:51 am #35299Coding convention that we try to stick to.
“_” (underscore) in front of private variables. Lower case first letter, then bumpy caps. _closeEnoughDistance
“t” in front of locally scoped variables. tCloseEnoughDistance
“a” in front of method parameters. public void Foo(int aCloseEnoughDistance)January 26, 2023 at 9:52 am #35300Nothing sacred about those - different people use different coding conventions. I’m usually the one who gets sloppy and violates it around here.
-
AuthorPosts
You must be logged in to reply to this topic.