[ECS] Reference an entity to another entity

Hello there,

I am currently trying to learn using the ecs. For my current project i want to build a tree-like structure. In normal OOB this would be easy but slow since the tree might get quite large. So there is a ‘HeadNode’ and ‘Node’ entities. Each should be able to hold a reference to multiple ‘Node’ Entities.

One possiblity might be an array of entitys as a component on the “parent-entity” though i can’t find the right types to introduce that as an component.

I am so far not able to find any useful information on this topic… Most posts are with a deprecated API or use some kind of ID-System as a workaround.

I’d be grateful for any information if this is even possible in ecs or if there is a method that might help me here. Let me know if you need more information on the project/problem.

Thanks in advance!

For anyone intrested:

this is solvable by adding a DynamicBuffer to the entity. The type of this buffer has to be a struct that implements IBufferElementDatawhich can have a member to hold an Entity.

basically like this:

[Serializable]
public struct ChildBuffer: IBufferElementData
{
    public Entity childNode;
}