GetEntity using identifier / Best way to find an associated entity

Is there a way to get an entity based on a specific identifier?

For instance, if I had a GlobalClock I could use GetSingleton() to retrieve its unique instance, but what I’d like to do is to get a Clock based on a unique identifier, so that I can bind the right Clock for the right job.

Think of a game with 5 planets with each their own Clock, with systems on each planet acting differently based on their local time.

This is where I’m stuck:

   protected override JobHandle OnUpdate(JobHandle inputDependencies)
        {
           
            var job = new UpdateSpansJob()
            {
                Time = GetSingleton<Clock>(), // TODO: Need to pass the right uid Clock there
                RealtimeDeltaTime = Time.deltaTime
            };
            return job.Schedule(this, inputDependencies);
        }

What is the best way to do this?

It’s a really simple thing but I don’t even know where to start… I’m struggling to manage dependencies and binding in ECS.

Create 5 entities each one containing Planet and Clock components then use IJobProcessData<Planet, Clock> to operate on those components.

What I mean is that on the same planet there are many components listening to the planet’s clock. I don’t know what’s the best way to “pass” that information to the systems…

For instance, 10 Volumes are on Planet A and change according to the Clock A time of day. 5 other Volumes, this time on Planet B, change according to the Clock B time of day. And so on.

The samples and examples lack scenarios like this where multiple systems need data processed by other systems. The answer must be simple but since there’s no documention I just don’t know where to start.

Sounds like you want a ClockReference ISharedComponentData that contains an entity corresponding to a planet’s clock. You then loop through each clock entity on the main thread, and for each clock schedule a job with that clock the same way you assigned it in your singleton example. The trick is that you also set your ISharedComponentData filter on your query for each clock so that you only process the entities which use the clock assigned to the job.

1 Like

Oh sh*t. I didn’t even know I could store entitites in ISharedComponentData. That’s powerful. Thanks :slight_smile: