News › Forums › RAIN › General Discussion and Troubleshooting › "GetItem()" the "Move Target Variable" Programmatically
This topic contains 3 replies, has 2 voices, and was last updated by VarunVP 2 months, 2 weeks ago.
-
AuthorPosts
-
May 20, 2022 at 12:11 am #40408
Hey guys!
I am trying to integrate Steering behaviours and RAIN for my AI. I use a custom action to set the TargetPoint variable for the steering script. Problem is that I want to get the Move Target Variable from the Waypoint Patrol node through script(using GetItem<T>(),) but it always returns a zero vector. How can I get variables that are defined in the BT interface?Here is the custom Action:
SteerForPoint vehicle; GameObject thisGameobject; BasicMemory aiMemory; public override void Start(RAIN.Core.AI ai) { thisGameobject = ai.Body; vehicle = thisGameobject.GetComponent<SteerForPoint>(); Debug.Log(ai.WorkingMemory.GetItem<Vector3>("moveToPoint")); //Displays 0 vector in console base.Start(ai); }
I observed that when I set a variable prior to this in the code, then it works as expected. I don’t understand what the problem is.
May 20, 2022 at 7:16 am #40410The console prints a 0 vector even though i have an expression assigning the variable. The scriptMoveTo variable is initialised in one action, and it is printed from another.That shouldn’t be much of a problem, should it?
The memory panel shows that the variable is correctly being updated. It’s the getting part in the action I am messing up in.InitialiseVariables.cs(The First action):
using UnityEngine; using System.Collections; using System.Collections.Generic; using RAIN.Action; using RAIN.Core; [RAINAction] public class InitialiseVariables : RAINAction { public GameObject thisGameObject; public override void Start(RAIN.Core.AI ai) { base.Start(ai); ai.WorkingMemory.SetItem<Vector3>("scriptMoveTo", Vector3.zero); ai.WorkingMemory.SetItem<GameObject>("thisGO", ai.Body); } public override ActionResult Execute(RAIN.Core.AI ai) { return ActionResult.SUCCESS; } public override void Stop(RAIN.Core.AI ai) { base.Stop(ai); } }
WaypointFollow.cs(3rd action):
using UnityEngine; using System.Collections; using System.Collections.Generic; using RAIN.Action; using RAIN.Core; using RAIN.Memory; using UnitySteer.Behaviors; [RAINAction] public class WaypointFollow : RAINAction { SteerForPoint vehicle; GameObject thisGameobject; public Vector3 point; BasicMemory aiMemory; public override void Start(RAIN.Core.AI ai) { base.Start(ai); } public override ActionResult Execute(RAIN.Core.AI ai) { Debug.Log(ai.WorkingMemory.GetItem<GameObject>("thisGO")); Debug.Log(ai.WorkingMemory.GetItem<Vector3>("scriptMoveTo")); thisGameobject = ai.Body; vehicle = thisGameobject.GetComponent<SteerForPoint>(); vehicle.TargetPoint = ai.WorkingMemory.GetItem<Vector3>("scriptMoveTo"); return ActionResult.SUCCESS; } public override void Stop(RAIN.Core.AI ai) { base.Stop(ai); } }
Please ask for any clarifications.
- This reply was modified 2 months, 3 weeks ago by VarunVP.
May 23, 2022 at 3:05 am #40425Hi,
In my experience, you need use ai.WorkingMemory.GetItemType() to get type first.
I guess the type is not Vector3.Best regards.
May 25, 2022 at 3:48 am #40428OH! By the way, I now use a completely different approach using A* and UnitySteer. Works like a charm. Thanks for the reply @Shimakaze!
-
AuthorPosts
You must be logged in to reply to this topic.