Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Authoring a list of waypoints in editor using Entities 1.0

Discussion in 'Entity Component System' started by ThermalFusion, Dec 4, 2022.

  1. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    900
    I've recently started looking into DOTS since the 1.0 prelease, so I'm pretty new to this stuff.
    Finding up to date information is pretty hard, since 1.0 is pretty new and a lot of things regarding authoring is changed in it, invalidating lots of old resources.

    What I'd like to do is author a list of waypoints in the editor with the aim of having entities walk along this path.
    I've considered FixedList, but I'm not sure this is the way to go, and I'd like to not be limited in the amount of points in the path.
    I've also considered BlobAssets, but I may want the points to be altered dynamically.
    I was thinking DynamicBuffer would be a good fit, but I can't find any information about how to author these and set them up in the editor with authoring components and bakers.

    I'd love some input on how to go about this problem.
    Thanks!
     
  2. FONTOoMas

    FONTOoMas

    Joined:
    Sep 26, 2015
    Posts:
    6
    Code (CSharp):
    1. public struct Waypoint : IBufferElementData
    2. {
    3.     public float3 position;
    4. }
    5.  
    6.  
    7. public class WaypointsAuthoring : MonoBehaviour
    8. {
    9.     public Transform[] waypoints;
    10.  
    11.     class WaypointsBaker : Baker<WaypointsAuthoring>
    12.     {
    13.         public override void Bake(WaypointsAuthoring authoring)
    14.         {
    15.             var buffer = AddBuffer<Waypoint>();
    16.  
    17.             for (int i = 0; i < authoring.waypoints.Length; i++)
    18.             {
    19.                 DependsOn(authoring.waypoints[i]);
    20.  
    21.                 buffer.Add(new Waypoint
    22.                 {
    23.                     position = authoring.waypoints[i].position
    24.                 });
    25.             }
    26.         }
    27.     }
    28. }
     
  3. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    900
    Fantastic, thank you very much!
     
  4. WAYN_Games

    WAYN_Games

    Joined:
    Mar 16, 2019
    Posts:
    893
    You may find my series usefull:
     
    bb8_1 and ThermalFusion like this.