The AI Rig is the controller for all the different elements of the AI. When created through the RAIN menu it will always be located on a child object under the GameObject.
Its main job is to update its elements, which it normally does through Unity messages (Awake, Start, Update, etc). In the event that you need more control over when the AI updates you can also turn off the default updates and take it over yourself. In general though, you don't use the rig directly, but use its elements instead.
Access to the AI Rig in code is no different then any MonoBehaviour.
using RAIN.Core; using UnityEngine; public class CustomAIRigComponent : MonoBehaviour { private AIRig _aiRig = null; void Awake() { _aiRig = GetComponentInChildren<AIRig>(); } }
To access the elements within an AI Rig, you have to use the AI property on the rig.
using RAIN.Core; using UnityEngine; public class CustomAIRigComponent : MonoBehaviour { private AIRig _aiRig = null; void Awake() { _aiRig = GetComponentInChildren<AIRig>(); } void Start() { // In all of these cases you can use the Property directly RAIN.Memory.BasicMemory tMemory = _aiRig.AI.WorkingMemory as RAIN.Memory.BasicMemory; RAIN.Minds.BasicMind tMind = _aiRig.AI.Mind as RAIN.Minds.BasicMind; // At least one of these would end up being null RAIN.Motion.BasicMotor tMotor = _aiRig.AI.Motor as RAIN.Motion.BasicMotor; RAIN.Motion.MecanimMotor tMecanimMotor = _aiRig.AI.Motor as RAIN.Motion.MecanimMotor; // Same here RAIN.Animation.BasicAnimator tAnimator = _aiRig.AI.Animator as RAIN.Animation.BasicAnimator; RAIN.Animation.MecanimAnimator tMecanimAnimator = _aiRig.AI.Animator as RAIN.Animation.MecanimAnimator; RAIN.Navigation.BasicNavigator tNavigator = _aiRig.AI.Navigator as RAIN.Navigation.BasicNavigator; RAIN.Perception.BasicSenses tSenses = _aiRig.AI.Senses as RAIN.Perception.BasicSenses; // And you can also access custom elements from here //_aiRig.AI.AddCustomElement() //_aiRig.AI.RemoveCustomElement() //_aiRig.AI.CustomElements } }
Here is an example of doing your own updates instead of Unity. The AI Rig already had its messages turned off in the editor ahead of time. Note that this is an advanced topic, normal use does not require relaying your own messages.
using RAIN.Core; using UnityEngine; public class CustomComponent : MonoBehaviour { private AIRig _aiRig = null; void Awake() { // We don't call anything here as the AI Rig may not be fully // initialized yet (Awake may or may not have been called) _aiRig = GetComponentInChildren<AIRig>(); } void Start() { _aiRig.AIAwake(); _aiRig.AIStart(); } void Update() { if (!_aiRig.UseFixedUpdate) _aiRig.AIUpdate(); } void LateUpdate() { _aiRig.AILateUpdate(); } void FixedUpdate() { if (_aiRig.UseFixedUpdate) _aiRig.AIUpdate(); } void OnAnimatorMove() { _aiRig.AIRootMotion(); } void OnAnimatorIK(int aLayerIndex) { _aiRig.AIIK(aLayerIndex); } }
In this case we are doing the exact same updates that the AI Rig would do on its own normally, but this was just for example.