Skip to main content

Minimal Setup

To set up a new system, you need two things.

  • Entity - An entity controlled by the steering system.
  • Steering System - The system which will control this entity.

Entity Setup

  1. Create a new prefab and add SteeringEntityAuthoring component to it.
  2. Optionally, add some mesh as a child to visualize the entity.
  3. Add a Movement2DAuthoring component for a Movement2DSystem.
  4. Create a new tag SampleEntityTagComponent for it. This tag tells the steering system which entities belong to it.
  5. In SteeringEntityAuthoring, select SampleEntityTagComponent from the dropdown and add it.
SampleEntityTag.cs
[SteeringEntityTag] // This will let the editor find this tag. 
public struct SampleEntityTagComponent : IComponentData {}

Your prefab should now match the following:

Minimal Steering Entity Prefab

Steering System Setup

  1. Right click into your folder and select Create/SteeringSystem.
  2. Rename the newly created asset to SampleSteeringSystemAsset, then select it and mark it as addressable.

Marking System as Addressable

  1. Create a new C# script which will load and run this system.
SampleSteeringSystem.cs
using SteeringAI.Core;
using Unity.Entities;

[UpdateInGroup(typeof(SteeringSystemsGroup))]
public partial class SampleSteeringSystem : BaseSteeringSystem
{
protected override string getAssetReferenceName()
{
return "Assets/Sample/SampleSteeringSystemAsset.asset";
}
}
warning

Make sure the path matches addressable address of the system, as shown in image above.

  1. Double click the SampleSteeringSystemAsset to open it in the editor window.
  2. Drag and drop your entity's prefab there.
  3. In the Main Tag dropdown, select SampleEntityTagComponent.
  4. The editor lists which components are missing on the entity. Click plus next to DesiredVelocityComponent to add it to the prefab.
  5. Select the Simple Behaviors tab and add GoForwardJobWrapper from the dropdown. This behavior makes entities go in their forward direction.
  6. On the right, add GoForwardComponent to the entity. It is used to parametrize the behavior.

Steering System Asset Set Up

The contents of your folder should now look like this:

Folder contents

Your prefab should look like this:

Entity prefab

Scene Setup

  1. Unity's ECS requires working with Subscenes. Right click into the scene hierarchy, select NewSubscene and save it.
  2. Drag and drop a few of these prefabs into the Subscene.
  3. By changing their Speed on GoForwardComponent you can change how fast they want to travel.
  4. With parameters of Movement2DAuthoring, you can change their maximum speed, acceleration etc.
  5. Hit play

The video shows a scene with three entities, each with different Speed on their GoForwardComponent.