Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

useTrait

useTrait<S>(target, trait): DeepReadonly<TraitRecord<S>> | undefined

Koota’s useTrait, which also reads a predicted or a core trait: target’s record of trait, again each time it changes, or undefined where it lacks it. A HUD reads a trait of the game’s own with it, such as useTrait(entity, ScoreTrait)?.points for a defineTrait("score", { points: 0 }). This signature reads a predicted or a core trait, and its type makes the record read-only, since only the step writes one.

Type Parameter
S extends Schema
Parameter Type
target Entity | null | undefined
trait PredictedTrait<S> | CoreTrait<S>

DeepReadonly<TraitRecord<S>> | undefined

useTrait<T>(target, trait): TraitRecord<T> | undefined

Any other trait, or a relation’s pair: its record as koota’s useTrait returns it, which the type does not make read-only.

Type Parameter
T extends Trait
Parameter Type
target World | Entity | null | undefined
trait T | RelationPair<T>

TraitRecord<T> | undefined