#Delete entities and components from entities in a System

1 messages · Page 1 of 1 (latest)

tall scroll
#

Hey, i am new to DOTS i'm currently making a graph system for a waypoint graph. I am implement a function to delete a connection between two nodes but i cannot figure out how to call delete component or delete entity... i only seem to have access to SystemAPI which has Gets but not Removes. This is my function so far:

//partial struct GraphSystem : ISystem 
    public void Disconnect(in Entity nodeA, in Entity nodeB)
    {
        if(!Is<Node>(nodeA))
            throw new System.Exception("Node A component not found for entity in GraphSystem::Disconnect");
        if(!Is<Node>(nodeB))
            throw new System.Exception("Node B component not found for entity in GraphSystem::Disconnect");

        //get the Connection:IBufferElementData buffer
        var conns = SystemAPI.GetBuffer<Connection>(nodeA);
        for(int i = 0; i < conns.Length; i++)
        {
            //for this connection to node A get the edge entity  
            var edge = SystemAPI.GetComponent<Edge>(conns[i].EdgeEntity);
            //confirm this edge connects to nodeB that we are trying to disconnect from
            if(edge.Node1 == nodeB || edge.Node2 == nodeB)
            {
                //SystemAPI..no delete options???
                //delete the edge entity
                //delete connection component from node entitys nodeA AND nodeB
                break;
            }
        }
    }

any one able to shed light on how i deleted the entity and components ?

true crow
#
  1. EntityManager.DestroyEntity()
  2. EntityCommandBuffer.DestroyEntity()

In parallel you can only use the second one, in general you can use the first one

tall scroll
#

i dont seem to have access to EntityManager though do i have to pass it in from the a script calling this function

#

i thought systems had access to the EM anyway but for some reason i do not

tall scroll
#

@true croware you certain EntityManager should be accessible in this situation

true crow
#

If it is a SystemBase then you have property EntityManager that you can use anywhere. In ISystem you can only acess it through SystemState in OnUpdate (and other callbacks). If another script is calling a method in a system it is supposed to be a SystemBase by design, as pure ECS is against direct references in systems

tall scroll
#

maybe my disconnect function should just be a static helper function or something instead

#

so its not tied to a system

true crow
#

You can either make it static or have a persistent entity with said event buffer or have a DynamicBuffer on all entities that can have this logic. If you use the latter you can populate DB in another system before and process it in your system without any structural changes

tall scroll
#

i see so the general rule is no system should reference another system

true crow
#

Yes

tall scroll
#

but what about monobehaviours calling on systems in order to link it to user input ?