So im learning a bit of DOTS at the moment and came across this line of code, i dont rly understand it, so i know entitys are the things in your world and i know what TranformUsageFlags do but i dont understand the AddComponent method? he is doing something there that i dont understand. I know a few basic stuff about the addcomponent like u need to tell what entity u want to add the component too and u need to tell the component wich position the entity must have but i dont understand what the prefab is? is it to tell it what sort of object it is? a cube or a circle etc..?
#Beginner needs help with understanding AddComponent
1 messages · Page 1 of 1 (latest)
A component can be almost anything. This is a custom component they've made called CubeSpawnerComponent that has those fields
A prefab in this case is just a gameobject (not part of DOTS or ECS). Since the Component is called CubeSpawner, I assume the prefab is the Cube to be Spawned 🤷♂️
The hybrid approach to ECS can use gameobjects as templates for creating entities. That way you can populate data via the inspector for entities just like the normal Unity workflow.
He might even just be spawning GameObjects, because that part is not shown in your screenshot, but I assume not
i thought components were the things u add to a gameobject in the inspector, i just cant grasp the thought that the component can be the cube?
That is in GameObject world
The video is talking about ECS world. They are separate ideas.
In GO world, Components inherit from MonoBehaviour as you likely know.
In ECS, they are actually a STRUCT, and generally inherit from IComponentData
Components are just data containers in ECS, and Systems are what act on the components. Entities are just a memory location id basically
Oohh... ok ok damn, i'll need to learn the ECS world first ig
so if i understand correctly, entitys are the identifiers to the boxes and the boxes are named components and in those boxes (components) u can have different functions
if u put it at a very simple explanation?
No
Entity is a container for components and can have any combination of those
ECS specifically splits logic from data (components)
So components are not meant to have it
Instead logic is declared in systems that have an ability to iterate any Combination of components
Try to reaf some articles on ECS that explain this pattern
Understanding thr basic goal of pattern will probably save you some trouble understanding different decisions from unity for dots
well ye i meant a container (:
so an entity can have any combination of components in it?
yes
so in this case, the code that i sent u, u have a prefab component and then a transform? because he gives a position to it?
in dots, baking handles transform baking for you
you just need to specify correct flags
or if you want to fully manually bake all transform components - you use ManualOverride flag
well, he sets the position of the spawning prefab in the code, is that not a transform?
no, he simply stored float3 field for later use in runtime
im not used to prefab being a component lol
that's not an equivalent of baked entity transform
prefab is not component
prefab is Entity with Prefab component
referenced as Entity field
so there is a component Prefab?
you can use components to store prefabs
or any other data that you want
so I assume that's what he does in example above
Aaah lol okay now i get it!
so he stores prefab in a component and the spawnposution too and the spawnrate etc...
so its not like im used to it, because in unity u can put components on gameobjects like a rigidbody2d or a transform component, in this case components are a sort of variables?
no, it's almost same thing as game objects regarding that. It's just that game object component are meant to have logic, while ECS ones don't
in ECS, you fully separate logic from data
this allows you scale horizontally
as in: any feature/assembly (even 3rd party one) can add systems that iterates existing components
i just dont understand what the prefab is in the component?
It's like saying public GameObject prefab; in a MonoBehaviour, you're referencing something that you're going to instantiate later
just that entities requires things to be referenced with Entity, so your field would be public Entity Prefab; spawned with like Entity spawned = EntityManager.Instantiate(Prefab);
But why is it in a component? a prefab isnt a component right?
where should it be?
the only way to have data in ECS - components
So u cant compare components from ecs to components like i normally saw in unity inspector?
bcs in components im used to u cant store prefabs...
but that isnt a component is it?
is a gameobject like a cube or a circle a component?
this is component
public class MonoBehaviour : Component
You seem to be struggling with Unity basics, check out beginner content on Unity Learn or find some tutorials about that. This really isn't relevant to #1062393052863414313 though.
but i dont understand what the prefab is in the component? is it just data u put into the component?
yes
aah so in this guy his code he is actually programming a new component
and he gives a few datas with it, a prefab a spawnposition
etc..
Yes : ☝️
Okay, thank u guys, i appreciate the help alot! ur right about learning the fundamentals of dots first because i lack them, but still a big thank you (: