Enfusion Script API
|
Immutable collection of replicated items.
Nodes describe the relations of singular Items within the system. They represent a single immutable structure that shares the lifetime properties, creation and initialization process.
You can think of them as a collection of entities and their components contained in a prefab instance. Those were designed to work together and probably to be spawned and destroyed at the same time.
The node itself is just an array of structures. You can fill it with your items as you see fit with one exception. The first inserted item had to be the Head item. This special item has to implement replication lifetime specific callbacks. These are for example able to recreate the contents of this node, destroy him, move him within the hierarchy of other nodes, save and load initialization data.
There are generally three types of nodes reflecting the environment from which they were registered. Each of them will receive a different type of RplId.
This is a really straight forward process but there is one caveat. You always have to be aware of when you are registering your node. In general there are only two phases influencing the registration process.
The node will get assigned some meta information right after it is created. Those are related to ownership and role. You can use these right from the start to build your logic around them. All of the contained Items will get an RplId assigned after the node gets registered. This is a unique identifier synchronized across the network.
During runtime the node along with the Head item serves as your access point to the replication related data and its features.
When this nodes becomes relevant to a client then a procedure called Node Streaming will be initiated. There will be whole chapter on this topic.
Once you know that the items in the node are getting deleted you should unregister the node from replication first. Otherwise there would be a whole lot of nasty crashes happening. You can free the items and eventually your node. Outgoing communication from your items would be properly finalized and destruction will be replicated to your items.
The nodes are really straight forward to use on their own. The most common use case would be the BaseRplComponent which combines both, the RplNode with Head item all together. Or the Connection which is not part of the entity component structure. Note that your logic does not have to be written in entities and components in order to use the replication and RplNodes you are completely free to structure your code however you like. The only limitation is that your items have to inherit from the BaseItem and properly use the related macros.