EntityService

This provides several features related to Entity.

# Methods

[{"index":"void Destroy(Entity entity)","0":"Destroys an entity."}]

[{"index":"void Destroy(Entity entity, float delaySeconds)","0":"Destroys the entity after delaySeconds (seconds)."}]

[{"index":"table GetEntitiesByPath(string worldPath)","0":"Returns an entity of the path corresponding to worldPath."}]

[{"index":"table GetEntitiesByTag(string tag)","0":"Finds and returns an entity with the tag corresponding to tag."}]

[{"index":"table GetEntitiesSpawnedByModel(Model model)","0":"Finds and returns an entity spawned by the corresponding model."}]

[{"index":"table GetEntitiesSpawnedByModelId(string modelId)","0":"Finds and returns an entity spawned by the model corresponding to the modelId."}]

[{"index":"Entity GetEntity(string id)","0":"Finds and returns entity by id."}]

[{"index":"Entity GetEntityByPath(string worldPath)","0":"Returns an entity of the corresponding worldPath."}]

[{"index":"Entity GetEntityByTag(string tag)","0":"Finds and returns an entity with the corresponding tag."}]

[{"index":"table GetSameModelEntities(Entity entity)","0":"Finds and returns entities with the same model as the entity."}]

[{"index":"boolean IsValid(Entity entity)","0":"Returns whether the entity is valid. The entity that's already been destroyed is invalid."}]

##### inherited from Service:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the event with the key-type event and the handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Events

[{"index":"EntityCreateEvent","0":"The event which takes place upon creation of an entity."}]

[{"index":"EntityDestroyEvent","0":"This event occurs when the Entity is destroyed."}]

# Examples

#### Destroy

This is an example of finding and deleting an Entity with a specific id.
    
    
    @Component
    script EntityDestroyer extends Component
        @ExecSpace("ServerOnly")
        method void DestroyTargetEntity(string id)
        local entity = _EntityService:GetEntity(id)
        _EntityService:Destroy(entity)
        end
    end
    

#### GetEntitiesByPath

This is an example of modifying the enable state of entities created in a specific path.
    
    
    @Component
    script EntityPathEnabler extends Component
        @ExecSpace("ServerOnly")
        method void EnablePathEntities(string path, boolean enable)
        local entities = _EntityService:GetEntitiesByPath(path)
        for k, v in pairs(entities) do
        	v.Enable = enable
        end
        end
    end
    

#### GetEntitiesByTag

This is an example of modifying the visible state of entities with a specific Tag using TagComponent.
    
    
    @Component
    script TaggedVisibilityController extends Component
        @ExecSpace("ServerOnly")
        method void VisibleTagEntities(string tag, boolean visible)
        local entities = _EntityService:GetEntitiesByTag(tag)
        for k, v in pairs(entities) do
        	v.Visible = visible
        end
        end
    end
    

#### GetEntitiesSpawnedByModelId

This is an example of making entities created with the MoveMonster model jump.
    
    
    @Component
    script MonsterJumper extends Component
        @ExecSpace("ServerOnly")
        method void JumpMoveMonsters()
        local entities = _EntityService:GetEntitiesSpawnedByModelId("model://movemonster")
        for k, v in pairs(entities) do
        	v.RigidbodyComponent:AddForce(Vector2(0.0, 5.0))
        end
        end
    end
    

# SeeAlso

  * RigidbodyComponent
  * [EntityService to Search for Entities](/docs?postId=201)