User Tools

Site Tools


rainelements:basicmind

Basic Mind

Properties

  • Use Unity Messages (Advanced): Whether the AI is initialized and updated by Unity or done manually.
  • Use Fixed Update (Advanced): Whether the AI responds to Unity Update or FixedUpdate messages. Only valid if Use Unity Messages is checked.
  • Is Active (Advanced): Whether the AI is currently updating.
  • Body: The GameObject that the AI will move and animate.
  • Mind: The type of mind used. Currently RAIN supports only one mind type, Basic Mind (this one). If you create your own Custom Mind you can select it here.

Actions

  • Open Behavior Editor: Opens the Behavior Tree Editor and displays the currently used behavior tree.

Usage

The Basic Mind is where behavior trees are executed. Aside from simply assigning the behavior tree you want to use, this is also where you can assign additional bindings used by the Tree Binding node.

Code

The main reason for accessing the Basic Mind through code would be to change out behavior trees at runtime. This is useful if you are constructing AI at runtime with a custom spawner.

using RAIN.BehaviorTrees;
using RAIN.Core;
using RAIN.Minds;
using System.Collections.Generic;
using UnityEngine;
public class JesterSpawner : MonoBehaviour
{
    [SerializeField]
    private GameObject _jesterPrefab = null;
    [SerializeField]
    private List<BTAsset> _behaviorAssets = new List<BTAsset>();
    private Stack<GameObject> _premadeJesters = new Stack<GameObject>();
    void Start()
    {
        // Make a some jesters
        for (int i = 0; i < 10; i++)
        {
            // Hide him and make him inactive
            GameObject tJester = (GameObject)Object.Instantiate(_jesterPrefab);
            if (_behaviorAssets.Count > 0)
            {
                // Set a random tree, and for the sake of a shorter example the bindings are empty
                AIRig tAIRig = tJester.GetComponentInChildren<AIRig>();
                ((BasicMind)tAIRig.AI.Mind).SetBehavior(_behaviorAssets[_behaviorAssets.Count - 1],
                                                        new List<BTAssetBinding>());
            }
            tJester.hideFlags = HideFlags.HideInHierarchy;
            tJester.SetActive(false);
            _premadeJesters.Push(tJester);
        }
    }
    public void SpawnJester(Vector3 aPosition, Quaternion aRotation)
    {
        // Setup our jester
        GameObject tOneJester = _premadeJesters.Pop();
        tOneJester.transform.position = aPosition;
        tOneJester.transform.rotation = aRotation;
        tOneJester.hideFlags = HideFlags.None;
        tOneJester.SetActive(true);
    }
}

See Also

rainelements/basicmind.txt · Last modified: 2022/08/13 18:13 (external edit)