Discussion about Entity Component System approach with Unreal Engine

Hi there !

I would like to read about some good Entity Component System implementation with Unreal Engine. Before that, I will expose my own approach and the issues I’ve met so far.

I’m not coming from the Unity world and I have some “purer” exprience of the ECS pattern. I’m usually separating data from logic, where one piece of logic (a System) is called upon entities that hold a set of data ( one or many components). It seems that this approach is quite hard to reproduce in Unreal (as in Unity), because of the Actor/Component architecture.

So I’ve merged logic and data in ActorComponents, which seems to be fine. Actor holding those components become the entities. This is not very pure, and is more like a merge between composition and inheritance, but on the paper, it seems to work well.

Here are my starting rules :

  • No logic in actors. That means no function, no event catched or called, no construction scripts, Actor are only component holders
  • Only one component of each type assigned to an actor (an entity)
  • Components may look for another component on their owner.

But this way I’ve ran into many issues.

First of all, it’s not easy to add and remove components at runtime, and it seems to be very cpu consuming (in blueprint). This is a major limitation because is tons of situation, components (systems) are adding/removing behaviors to an entity and communicating via data. For now, the best solution I found was to create some common component to hold temporary data or to call event, so that components can communicate. Imagine a EventComponent with a long list of event dispatchers on which each component can bind. Not very elegant, and multithreading killer.

The second issue i’ve run into was the impossibility to order components on an Actor. You can’t predict or decide wich event tick of wich component will run first. For this problem, I can’t see any solution because of the Actor pattern. Components hold both data and logic and it should be weird to have to order them on each entity. In a pure approach, you decide the execution order of the systems, and if they can or cannot be run asynchronously, for multiprocessor optimisation. Unity have the same issue, for what I know.

I have been annoyed by the lack of construction script in components. I don’t see any reason why they miss this feature. That said, it have been easy to declare a “init” function in the base component, they call it in Actor construction script for each component owned. This allows, for eaxemple, to make particle component visible in the editor and not only in game.

I finaly had a more odd issue when I asked component to modify their owning Actor, but this is discussed in the answer hub here : Code in actor event tick can't be moved to component event tick without issue - Blueprint - Epic Developer Community Forums.

I would love to read about your own implementation of ECS approach, and I would be glad to know about your solutions for the problem I’ve met. I beleive that Epic is currently working on an ECS impmlementation for Unreal Engine but I’ve been unable to read more on the subject. If your have some ressources, news or other post, please share !

Thanks for reading !

I think you’ll find that there isn’t enough exposed to the Blueprint system to pull this off properly.
You’d have better luck via C++ where you can get in an re-write/change underlying code.

Thanks for this advice. I haven’t faced any issue specificialy due to Blueprint system (or so I think), but this post may be in the wrong place of the forum. Would you (or another moderator) mind moving it to the C++ sub forum, or wherever you think this subject have the best chance of being discussed?

Thnks in advance.