Skip to content
ctreffs edited this page Oct 20, 2020 · 7 revisions

Entity

Entity

public struct Entity

An entity is a general purpose object. It only consists of a unique id (EntityIdentifier). Components can be assigned to an entity to give it behavior or functionality. An entity creates the relationship between all it's assigned components.

Inheritance

CustomDebugStringConvertible, CustomStringConvertible, Equatable

Properties

identifier

The unique entity identifier.

var identifier: EntityIdentifier

numComponents

Returns the number of components for this entity.

var numComponents: Int

hasComponents

Checks if this entity has any components.

var hasComponents: Bool

description

var description: String

debugDescription

var debugDescription: String

Methods

get()

@inlinable public func get<C>() -> C? where C: Component

get(component:)

@inlinable public func get<A>(component compType: A.Type = A.self) -> A? where A: Component

get(components:_:)

@inlinable public func get<A, B>(components _: A.Type, _: B.Type) -> (A?, B?) where A: Component, B: Component

get(components:_:_:)

@inlinable public func get<A, B, C>(components _: A.Type, _: B.Type, _: C.Type) -> (A?, B?, C?) where A: Component, B: Component, C: Component

get(valueAt:)

Get the value of a component using the key Path to the property in the component.

@inlinable public func get<Comp, Value>(valueAt componentKeyPath: KeyPath<Comp, Value>) -> Value where Comp: Component

A Comp instance must be assigned to this entity!

Parameters

  • componentKeyPath: The KeyPath to the property of the given component.

get(valueAt:)

Get the value of a component using the key Path to the property in the component.

@inlinable public func get<Comp, Value>(valueAt componentKeyPath: KeyPath<Comp, Value?>) -> Value? where Comp: Component

A Comp instance must be assigned to this entity!

Parameters

  • componentKeyPath: The KeyPath to the property of the given component.

set(value:for:)

Set the value of a component using the key path to the property in the component.

@inlinable @discardableResult public func set<Comp, Value>(value newValue: Value, for componentKeyPath: ReferenceWritableKeyPath<Comp, Value>) -> Bool where Comp: Component & DefaultInitializable

Behavior:

  • If Comp is a component type that is currently not assigned to this entity, a new instance of Comp will be default initialized and newValue will be set at the given keyPath.

Parameters

  • newValue: The value to set.
  • componentKeyPath: The ReferenceWritableKeyPath to the property of the given component.

Returns

Returns true if an action was performed, false otherwise.

set(value:for:)

Set the value of a component using the key path to the property in the component.

@inlinable @discardableResult public func set<Comp, Value>(value newValue: Value?, for componentKeyPath: ReferenceWritableKeyPath<Comp, Value?>) -> Bool where Comp: Component & DefaultInitializable

Behavior:

  • If Comp is a component type that is currently not assigned to this entity, a new instance of Comp will be default initialized and newValue will be set at the given keyPath.

Parameters

  • newValue: The value to set.
  • componentKeyPath: The ReferenceWritableKeyPath to the property of the given component.

Returns

Returns true if an action was performed, false otherwise.

createEntity()

@discardableResult public func createEntity() -> Entity

createEntity(with:)

@discardableResult public func createEntity(with components: Component) -> Entity

createEntity(with:)

@discardableResult public func createEntity<C>(with components: C) -> Entity where C: Collection, C.Element == Component

has(_:)

Checks if a component with given type is assigned to this entity.

public func has<C>(_ type: C.Type) -> Bool where C: Component

Parameters

  • type: the component type.

has(_:)

Checks if a component with a given component identifier is assigned to this entity.

public func has(_ compId: ComponentIdentifier) -> Bool

Parameters

  • compId: the component identifier.

assign(_:)

Add one or more components to this entity.

@discardableResult public func assign(_ components: Component) -> Entity

Parameters

  • components: one or more components.

assign(_:)

Add a component to this entity.

@discardableResult public func assign(_ component: Component) -> Entity

Parameters

  • component: a component.

assign(_:)

Add a typed component to this entity.

@discardableResult public func assign<C>(_ component: C) -> Entity where C: Component

Parameters

  • component: the typed component.

assign(_:)

@discardableResult public func assign<C>(_ components: C) -> Entity where C: Collection, C.Element == Component

remove(_:)

Remove a component from this entity.

@discardableResult public func remove<C>(_ component: C) -> Entity where C: Component

Parameters

  • component: the component.

remove(_:)

Remove a component by type from this entity.

@discardableResult public func remove<C>(_ compType: C.Type) -> Entity where C: Component

Parameters

  • compType: the component type.

remove(_:)

Remove a component by id from this entity.

@discardableResult public func remove(_ compId: ComponentIdentifier) -> Entity

Parameters

  • compId: the component id.

removeAll()

Remove all components from this entity.

public func removeAll()

destroy()

Destroy this entity.

public func destroy()

makeComponentsIterator()

Returns an iterator over all components of this entity.

@inlinable public func makeComponentsIterator() -> ComponentsIterator

==(lhs:rhs:)

public static func ==(lhs: Entity, rhs: Entity) -> Bool
Clone this wiki locally