How to access GameObject and it's components from an ECS Systems?

Hi!
In my project I have multiple cameras with different values of Field Of View which can also be dynamically changed. Also I need to switch active camera (deactivate one and activate another during the runtime). All of this makes me access these authoring Camera components so I can manipulate their values.

Is there ways to access authoring components of specific GameObjects from ECS Systems?

P.S. Obviously I can’t just use Singleton link because cameras more than one


1 Answer

1

I answered very similar question here:


ObjectsToEntity.cs is your authoring-like component that maintains an Entity with references to any UnityEngine.Object you want.

ObjectsToEntity.cs

In short, this is how accessing Camera component would look like on ECS side:

Camera cam = EntityManager.GetComponentObject<Camera>(entity);
ISystem example

→ More details in the linked thread.