Skip to content

YaEntity

YaEntity identifies an object in games. YaEntity can only function when the YaEntity module (https://developer.yahaha.com/manual/yahaha-studio-manual/scripting/module/module-reference/YaEntity/) is added to the same object.

Functions

number GetEntityId()

ReturnsThe ID number
Get the entity ID for the entity.
1
2
local entityId = script:SelfEntity():GetEntityId()
print("This entity's entity ID is " .. entityId)

boolean IsEmpty()

ReturnsTrue if the entity value represents no entity
Checks whether the entity value represents an entity. Some APIs can return an entity that is empty (e.g., physics query APIs). In that case, use this API to check the result.
1
2
3
4
5
6
7
local raycastResult = PhysicsAPI.RaycastSingle(float3.New(0, 0, 0), float3.New(0, 0, 1), YaQueryParameter.Instance())
if raycastResult.Entity:IsEmpty()
then
    print("Could not find any entity")
else
    print("Found entity " .. raycastResult.Entity.EntityId)
end

boolean IsAlive()

ReturnsFalse if the entity value represents an eliminated entity or an empty entity, otherwise true
Checks whether the entity value represents an existing entity (different from the idea of method IsEmpty). If an entity value is stored for latter usage, this method can help check whether the entity still exists (if users are not sure about the existence). Empty entities always not alive.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
local position = script:GetYaComponent("YaMovableComponent"):GetGlobalPosition()
local raycastResult = PhysicsAPI.RaycastSingle(float3.New(position.x, position.y, position.z + 4), float3.New(0, 0, 1), YaQueryParameter.Instance():QueryAllPhysicsLayer())
if raycastResult.Entity:IsEmpty()
then
    print("Could not find any entity")
else
    print("Found entity " .. raycastResult.Entity.EntityId)
    local waitEvent = YaTime:WaitFor(10)
    EventHelper.AddListener(waitEvent, "TimeEvent", function ()
        if raycastResult.Entity:IsAlive()
        then
            print("Entity is still alive")
        else
            print("Entity is eliminated")
        end
    end)
end

boolean HasTag(string tag)

Returnstrue if the YaEntity has the tag.
Checks if the YaEntity has the tag.
  • tag The name of the tag

YaEntity YaEntity.GetEntityById(number entityId)

ReturnsThe corresponding entity
Get the entity by the entity ID. Under the case the entity does not exist, the IsEmpty method would return true.
  • entityId The entity ID that was retrieve by the YaEntity.EntityId field

Array<YaEntity> YaEntity.GetEntitiesByTag(string tag)

Returnsan array of YaEntities.
Gets all YaEntities that contain the specified tag.
  • tag The name of the tag

float3 GetPosition()

ReturnsThe position of the entity
Gets the entity's position in local space.