Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    Entity Class

    Namespace: Stride.Engine
    Assembly: Stride.Engine.dll

    Game entity. It usually aggregates multiple EntityComponent

    System.Object → DisposeBase → ComponentBase → Entity
    Derived from Entity:

    [ContentSerializer(typeof(Entity.EntityContentSerializer))]
    [DataSerializer(typeof(Entity.EntitySerializer))]
    [DataStyle(DataStyle.Normal)]
    [DataContract("Entity")]
    public sealed class Entity : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder, IEnumerable<EntityComponent>, IEnumerable, IIdentifiable
    Name Description
    Constructors
    Entity()

    Create a new Entity instance.

    Entity(Vector3, String)

    Create a new Entity instance having the provided name and initial position.

    Entity(String)

    Create a new Entity instance having the provided name.

    Properties
    Components

    The components stored in this entity.

    EntityManager

    The entity manager which processes this entity.

    Id
    Name
    Scene

    The scene this entity is in.
    Setting this to null will remove the entity from the scene and detach it from its parent if it has one.

    Transform

    Gets or sets the Transform associated to this entity. Added for convenience over usual Get/Set method.

    Methods
    Add(EntityComponent)

    Adds the specified component using the .

    Get<T>()

    Gets the first component of the specified type.

    Get<T>(Int32)

    Gets the index'th component of the specified type. See remarks.

    GetAll<T>()

    Gets all components of the specified type.

    GetEnumerator()

    Gets the enumerator of EntityComponent

    GetOrCreate<T>()

    Gets or create a component with the specified key.

    Remove(EntityComponent)

    Removes the specified component.

    Remove<T>()

    Removes the first component of the specified type or derived type.

    RemoveAll<T>()

    Removes all components of the specified type or derived type.

    ToString()
    Explicit Interface Implementations
    IEnumerable<EntityComponent>.GetEnumerator()
    IEnumerable.GetEnumerator()
    | Improve this Doc View Source

    Constructors


    Entity()

    Create a new Entity instance.

    public Entity()

    Entity(Vector3, String)

    Create a new Entity instance having the provided name and initial position.

    public Entity(Vector3 position, string name = null)
    Parameters
    Type Name Description
    Vector3 position

    The initial position of the entity

    System.String name

    The name to give to the entity


    Entity(String)

    Create a new Entity instance having the provided name.

    public Entity(string name)
    Parameters
    Type Name Description
    System.String name

    The name to give to the entity

    | Improve this Doc View Source

    Properties


    Components

    The components stored in this entity.

    [DataMember(100, DataMemberMode.Content)]
    public EntityComponentCollection Components { get; }
    Property Value
    Type Description
    EntityComponentCollection

    EntityManager

    The entity manager which processes this entity.

    public EntityManager EntityManager { get; }
    Property Value
    Type Description
    EntityManager

    Id

    [DataMember(-10)]
    [Display(null, null, Browsable = false)]
    public Guid Id { get; set; }
    Property Value
    Type Description
    System.Guid

    Name

    [DataMember(0)]
    public override string Name { get; set; }
    Property Value
    Type Description
    System.String
    Overrides
    ComponentBase.Name

    Scene

    The scene this entity is in.
    Setting this to null will remove the entity from the scene and detach it from its parent if it has one.

    public Scene Scene { get; set; }
    Property Value
    Type Description
    Scene

    Transform

    Gets or sets the Transform associated to this entity. Added for convenience over usual Get/Set method.

    public TransformComponent Transform { get; }
    Property Value
    Type Description
    TransformComponent
    | Improve this Doc View Source

    Methods


    Add(EntityComponent)

    Adds the specified component using the .

    public void Add(EntityComponent component)
    Parameters
    Type Name Description
    EntityComponent component

    The component.

    Exceptions
    Type Condition
    System.ArgumentNullException

    component


    Get<T>()

    Gets the first component of the specified type.

    public T Get<T>()
        where T : EntityComponent
    Returns
    Type Description
    T

    The component or null if does no exist

    Type Parameters
    Name Description
    T

    Type of the component


    Get<T>(Int32)

    Gets the index'th component of the specified type. See remarks.

    public T Get<T>(int index)
        where T : EntityComponent
    Parameters
    Type Name Description
    System.Int32 index

    The index'th component to select.

    Returns
    Type Description
    T

    The component or null if does no exist

    Type Parameters
    Name Description
    T

    Type of the component

    Remarks
    • If index > 0, it will take the index'th component of the specified T.
    • An index == 0 is equivalent to calling Get<T>()
    • if index < 0, it will start from the end of the list to the beginning. A value of -1 means the first last component.

    GetAll<T>()

    Gets all components of the specified type.

    public IEnumerable<T> GetAll<T>()
        where T : EntityComponent
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<T>

    The component or null if does no exist

    Type Parameters
    Name Description
    T

    Type of the component


    GetEnumerator()

    Gets the enumerator of EntityComponent

    public FastCollection<EntityComponent>.Enumerator GetEnumerator()
    Returns
    Type Description
    FastCollection.Enumerator<>

    GetOrCreate<T>()

    Gets or create a component with the specified key.

    public T GetOrCreate<T>()
        where T : EntityComponent, new()
    Returns
    Type Description
    T

    A new or existing instance of {T}

    Type Parameters
    Name Description
    T

    Type of the entity component


    Remove(EntityComponent)

    Removes the specified component.

    public void Remove(EntityComponent component)
    Parameters
    Type Name Description
    EntityComponent component

    Remove<T>()

    Removes the first component of the specified type or derived type.

    public void Remove<T>()
        where T : EntityComponent
    Type Parameters
    Name Description
    T

    Type of the component


    RemoveAll<T>()

    Removes all components of the specified type or derived type.

    public void RemoveAll<T>()
        where T : EntityComponent
    Type Parameters
    Name Description
    T

    Type of the component


    ToString()

    public override string ToString()
    Returns
    Type Description
    System.String
    Overrides
    ComponentBase.ToString()
    | Improve this Doc View Source

    Explicit Interface Implementations


    IEnumerable<EntityComponent>.GetEnumerator()

    IEnumerator<EntityComponent> IEnumerable<EntityComponent>.GetEnumerator()
    Returns
    Type Description
    System.Collections.Generic.IEnumerator<EntityComponent>

    IEnumerable.GetEnumerator()

    IEnumerator IEnumerable.GetEnumerator()
    Returns
    Type Description
    System.Collections.IEnumerator

    Inherited Members

    ComponentBase.Tags
    ComponentBase.Destroy()
    ComponentBase.ICollectorHolder.Collector
    ComponentBase.OnNameChanged()
    DisposeBase.Dispose()
    DisposeBase.IsDisposed
    DisposeBase.IReferencable.ReferenceCount
    DisposeBase.IReferencable.AddReference()
    DisposeBase.IReferencable.Release()
    DisposeBase.OnAddReference()
    DisposeBase.OnReleaseReference()

    Extension Methods

    EntityExtensions.Clone(Entity)
    EntityExtensions.GetChildren(Entity)
    EntityExtensions.Enable<T>(Entity, Boolean, Boolean)
    EntityExtensions.EnableAll(Entity, Boolean, Boolean)
    EntityTransformExtensions.AddChild(Entity, Entity)
    EntityTransformExtensions.RemoveChild(Entity, Entity)
    EntityTransformExtensions.RemoveChild(Entity, Guid)
    EntityTransformExtensions.GetChild(Entity, Int32)
    EntityTransformExtensions.GetParent(Entity)
    EntityTransformExtensions.SetParent(Entity, Entity)
    EntityTransformExtensions.FindChild(Entity, String)
    EntityTransformExtensions.FindRoot(Entity)
    ComponentBaseExtensions.DisposeBy<T>(T, ICollectorHolder)
    ComponentBaseExtensions.RemoveDisposeBy<T>(T, ICollectorHolder)
    EnumerableExtensions.IsNullOrEmpty(IEnumerable)
    EnumerableExtensions.ForEach<T>(IEnumerable, Action<T>)
    EnumerableExtensions.ForEach<T>(IEnumerable<T>, Action<T>)
    EnumerableExtensions.IndexOf<T>(IEnumerable<T>, Func<T, Boolean>)
    EnumerableExtensions.LastIndexOf<T>(IEnumerable<T>, Func<T, Boolean>)
    EnumerableExtensions.NotNull<T>(IEnumerable<T>)
    EnumerableExtensions.ToHashCode<T>(IEnumerable<T>)
    • Improve this Doc
    • View Source
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation