Unity vs Unreal 4 approach to entity-component pattern

Started by
2 comments, last by _the_phantom_ 8 years, 3 months ago

Unity and Unreal engine 4 both have different approaches to the Entity-Component pattern.

Unity's approach is a bit closer to the standard definition, where 'GameObjects' are purely a sum of their components. Components are also very fine-grained ('RigidBody' and 'MeshCollider' and totally distinct, for example), and each does very little on its own.

Unreal on the other hand, has Components (SceneComponents, specifically) acting more like independent objects which may be placed and moved independently of their owning 'Actor' and the other components it's composed of. Each component also contains a lot more behavior, where a 'StaticMeshComponent' will have rendering, collision, and physics bundled up together. Additionally, the Actor class itself may be subclassed to create specific configurations of components, as well as implementing behavior.

Personally, while Unity's approach is a bit more "pure" from an engineering perspective, I've found Unreal's approach a lot more intuitive and pleasant to work with when designing objects (this may be partly due to Unreal having a much better tool experience). However, I haven't had an opportunity to work with Unreal a whole lot yet, so there may be large drawbacks I haven't encountered.

Ultimately, I think Unity may be a bit too rigid in its approach (Unity basically shoves everything into "Components", which can feel a bit unnatural at times), but Unreal's approach smells a bit like a holdover from the days of over-using inheritance, which makes me a little wary.

What are your thoughts?

Advertisement

I haven't worked with UE4 much, and am only beginning to feel comfortable with Unity, but one thing I'm beginning to feel about Unity's framework is that the entities and components are structured very nicely, but they hide too many details of the underlying systems for my liking. How is each component stored in memory? How does each system iterate over its specific component instances, or its combination of multiple interrelated components? Ideally, not every component would be stored identically, or iterated over identically, or lookup up identically, et cetera.

It feels like the Unity team has done a pretty good job of adhering to the data-oriented design philosophy in some regards, but they've made many of the design choices already and hidden the details within the private portions of the engine. Which means that they've had to make generic design choices that work well enough for as many game elements and as many types of games as possible. Which then severely weakens a developer's ability to exercise data-oriented design effectively. The design depends on the data, and different games and different systems have and use data in vastly different ways, but a Unity developer can only do so much when trying to design appropriately. It's like Unity is so close to awesome, and yet so far away.

So I don't think that Unity has problems because of its purity with the ECS concept, but because of the genericity forced by the closed nature of the engine. Despite that, and as implied above, I do find it to be adequate. It's good enough, but it doesn't achieve the awesomeness that I think its overall design grants it the potential to become.

"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke

I think Unity's is a step in the right direction, but it's very difficult to make components interact when they are entirely encapsulated. I find that it's better to have components be pure data, with systems operating over them, potentially multiple components at once, e.g. an IntegrationSystem that integrates velocity into position, but only if both components are present.

"So there you have it, ladies and gentlemen: the only API I’ve ever used that requires both elevated privileges and a dedicated user thread just to copy a block of structures from the kernel to the user." - Casey Muratori

boreal.aggydaggy.com

but Unreal's approach smells a bit like a holdover from the days of over-using inheritance, which makes me a little wary.


While it shouldn't make you 'wary' as such you are correct that the larger classes are a hold over from the pre-UE4 days.
While it does give you easy canned classes to work with it does however present problems as some of those classes don't derive from the right part of the inheritance tree so you couldn't, for example, treat an Actor as a SceneComponent in an interchangeable way which leads to complications both in the code and in the usage pattern and the designer ends up having to remember special rules.

I believe there is effort afoot to convert things like StaticMeshRenderer and the like to proper component systems so that problem goes away (there are a number of classes which share this work flow/looks-like-a-component-but-sint problem) but I've no idea how far along that work is.

This topic is closed to new replies.

Advertisement