Component Registration
Component Registration, this is how you register and change components in arch.
Last updated
Was this helpful?
Component Registration, this is how you register and change components in arch.
Last updated
Was this helpful?
All components are recorded and stored in the ComponentRegistry
. It primarily stores meta data such as the size and types of the components, which are then queried at runtime as a compile-time static or manually to access the underlying arrays of and and more.
These metadata are expressed as ComponentType
, a struct that you may have seen here and there before. It combines the component with its most important metadata and is used precisely for this purpose.
There are some cases where you might prefer to register your components yourself because YOU simply know more than Arch and C# at that moment. For example, C# has problems with managed structs or even classes here and there. This feature is also useful for AOT.
Alternatively, you can also call up the generic variants such as...
You can not only register components but also receive, replace and remove.
So now you've registered all these wonderful components... but how does Arch get to it under the hood? And how can you do it yourself? Of course this works by accessing the ComponentRegistry
, but this is always associated with a lookup. There has to be an more efficient way!
Using the Component<T0...T25>
is one way. This is a compile-time static class that provides all meta-data for the passed Component
directly, without any lookups! And the best, it comes with up to 25 generic overloads!
Cool, right? Now you got the tools to build almost everything you want on your own! E.g. custom librarys and extensions!