Why components have tranform?

#1
I can understand the ECS in Unity, but when I switched to CryEngine, I have trouble understanding the design of its ECS. I know that different engines have different designs. Design is not physical rules, it is by human. But now, I just cannot understand the necessity of components having transform. (on the contrary, it is easy to understand that entities can have transform.)

Could you help me? Thanks in advance.

Re: Why components have tranform?

#2
Hello!

Components have transforms so they can have separate transforms than the parenting Entity. Remember that an Entity is basically just an ID in a game world, with a position/rotation/scale (transform), and is made up of components. Those components are things like logic, visual objects like meshes, bounding boxes, audio players etc.. Those components may want a different position/rotation/scale than the Entity or other components. Unity's approach is to have multiple gameobjects with components in a parent-child relationship in order to have different transforms for the different components, whereas other Engines like CRYENGINE let you modify the transform of the components instead, so you can have all the components on just the single entity, avoiding the need for a hierarchy of entities. That is still an option, if you wanted to go that route, but CRYENGINE offers the less complicated structure.

A use case for the explained, would be a player character and camera. You'll notice in the CRYENGINE First/Third Person Templates, the Player Entity, has an advanced animation component that is used for the character model and animations, and the camera component. These components are on the same Entity. If the camera component shared the position/rotation/scale of the entity, it would be at the feet of the character, because that would be the position of the Entity typically, instead of on the neck or just behind and above the shoulder. To have this same effect in Unity, you'd have to attach the camera to a separate GameObject than the Character GameObject, move that GameObject to the appropriate position and attach the GameObject to the Character's GameObject. In CRYENGINE and other engines that allow component transforms, your components can have whatever position/rotation/scale you need, and you don't need a separate Entity or GameObject to have it.

Re: Why components have tranform?

#3
Hello!

Components have transforms so they can have separate transforms than the parenting Entity. Remember that an Entity is basically just an ID in a game world, with a position/rotation/scale (transform), and is made up of components. Those components are things like logic, visual objects like meshes, bounding boxes, audio players etc.. Those components may want a different position/rotation/scale than the Entity or other components. Unity's approach is to have multiple gameobjects with components in a parent-child relationship in order to have different transforms for the different components, whereas other Engines like CRYENGINE let you modify the transform of the components instead, so you can have all the components on just the single entity, avoiding the need for a hierarchy of entities. That is still an option, if you wanted to go that route, but CRYENGINE offers the less complicated structure.

A use case for the explained, would be a player character and camera. You'll notice in the CRYENGINE First/Third Person Templates, the Player Entity, has an advanced animation component that is used for the character model and animations, and the camera component. These components are on the same Entity. If the camera component shared the position/rotation/scale of the entity, it would be at the feet of the character, because that would be the position of the Entity typically, instead of on the neck or just behind and above the shoulder. To have this same effect in Unity, you'd have to attach the camera to a separate GameObject than the Character GameObject, move that GameObject to the appropriate position and attach the GameObject to the Character's GameObject. In CRYENGINE and other engines that allow component transforms, your components can have whatever position/rotation/scale you need, and you don't need a separate Entity or GameObject to have it.
Thanks, Drake. Your explanation is really important for me to understand the ECS in CRYENGINE. Now, I can understand the `why' behind the design.

Now, I am building some customized components based on the project template. This is a camera entity(player). but I cannot understand the concept GamePlugin well. Is it always necessary? What is the function of GameServer project? It is not clear for me.

If I create an empty entity in Sandbox, then attach MyPlayer component(it is responsible to update the orientation of the camera component and the position & orientation of the entity), does it still need the GamePlugin?

At last, I saw `slot' in the `IEntity` source code, what is a slot?

Sorry for my bad English, sorry for so many questions :(
Last edited by Yanpeng_Li on Thu Mar 17, 2022 10:07 am, edited 1 time in total.

Re: Why components have tranform?

#4
Please visit our documentation page for a more in-depth breakdown of the engine and features.

Here's the main docs: https://docs.cryengine.com/

Plugin: https://docs.cryengine.com/display/CEMA ... gin+System

Slots: https://docs.cryengine.com/display/CEPR ... nd+Effects

For a bit more information on the GamePlugin, it is required in order to link your code to the engine. Without it, there is no way to tell the engine to use your custom code, and there is no way for your custom code to interact with the engine library, that is, without downloading the full source from Github and applying your changes directly to the source build. By using Plugins, you're able to place all your code in a separate section that has access to the other code, and is capable of implementing its own functionality. This also allows you to avoid making changes directly to the full source code, and to port your code to other projects easily.

Re: Why components have tranform?

#6
After reading the document about slot(I have to say, it explains too little) and some source codes(including its type reflection, IEntity, IEntityComponent, CEntity), I still cannot understand what is a slot, why we need that concept. I saw we can load geometry, light, and other categories using slots, but why not use components?

Re: Why components have tranform?

#7
I encourage a few re-reads of the first link I posted. That page is very informative on what slots are and how they work.

To answer you question regarding using components, you do use them. The components already written by Crytek manipulate the slots directly, so you do not need to code your own custom component to manipulate the slots, unless the provided components do not offer the functionality you want. I'd recommend having a look through some of the components to see how they manipulate the slots in order to attach the necessary objects to the entity. A couple to look into would be the BaseMeshComponent and the PointLightComponent.

https://github.com/CRYTEK/CRYENGINE/blo ... omponent.h

https://github.com/CRYTEK/CRYENGINE/blo ... ponent.cpp

Who is online

Users browsing this forum: No registered users and 1 guest

cron