Is there a better way to add objects (Sprites) to Entities than through Monobehaviours?

Is there a way to have a class or struct containing things like Sprites, AnimatorControllers, etc. without having to manage Monobehaviour?

The problem I have with the Monobehaviour approach is that I am forced to add a component to a gameobject in order to be able to add it to an Entity via AddComponentObject. Sometimes I just want to store a sprite for later use and therefore do not need the bloat of Monobehaviour.

It would be nice to have something like IComponentObjectData structs that can hold Unity objects references. It would be easier to convert once their DOTS-friendly equivalents are rolled out.

The next DOTS release supposedly will have an IComponent for possibly this use case. However, I don’t know what an IComponent will actually be. I can think of three different possibilities:

  • A class type that gets added or removed using Add/RemoveComponentObject.
  • A class type that gets pooled.
  • A struct type that can hold non-blittable type references.

I have a custom implementation of the third option which I will release if Unity’s IComponent GC behavior is inferior.

1 Like