Vixen
02b45cc4
csharp
public abstract class Behavior

The MonoBehaviour-shaped API: a class attached to an entity with lifecycle callbacks.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

protected override void Start() => Run(Patrol()); async Coroutine Patrol() { while (true) { await MoveTo(LeftPost); await Seconds(2f); await MoveTo(RightPost); await Seconds(2f); } } The infinite loop is not a leak: the behaviour's destruction cancels it at its next resume point, and the while unwinds through whatever finally blocks are in the way.

Why one base class rather than Stride's two. Stride splits SyncScript, which has Update, from AsyncScript, whose whole life is one Execute loop. A behaviour usually wants both — a per-frame Update that reads input, and a coroutine that plays out a door opening — and the split forces the choice at the moment a class is declared, which is the moment least is known. Here every behaviour can do both, and a coroutine is something you start rather than something you are.

Fields and properties (14)

  • public int CoroutineGeneration

    Bumped by StopCoroutines. Everything suspended under an older value cancels.

  • public CoroutineScheduler Coroutines

    The scheduler this behaviour's coroutines run on.

  • public Entity Entity

    The entity this is attached to.

  • public World World

    The world the entity lives in.

  • public bool IsDestroyed

    Whether the behaviour has been destroyed, or its entity has.

  • public bool Enabled

    Whether Update runs. Changing it queues OnEnable or OnDisable for the next lifecycle drain rather than calling it here.

  • public bool IsAwake

    Whether the behaviour has had Awake called.

  • public bool IsStarted

    Whether the behaviour has had Start called.

  • public GameTime Time

    The clock for the pass this behaviour is running in.

  • public Transform Transform

    A façade over the entity's transform.

  • public Vector3 Position

    Position in world space.

  • public Vector3 LocalPosition

    Position relative to the parent.

  • public Quaternion Rotation

    Rotation in world space.

  • public Quaternion LocalRotation

    Rotation relative to the parent.

Methods (20)

  • public CoroutineHandle Run(Coroutine coroutine)

    Starts a coroutine owned by this behaviour.

  • public void StopCoroutines()

    Cancels every coroutine of this behaviour at its next resume point.

  • public CoroutineAwaitable NextFrame(ResumePoint? point = null)

    Waits for the next occurrence of a resume point.

  • public CoroutineAwaitable Seconds(float seconds, ResumePoint? point = null)

    Waits an amount of scaled game time. A paused game does not advance it.

  • public CoroutineAwaitable UnscaledSeconds(float seconds, ResumePoint? point = null)

    Waits an amount of unscaled time, which a pause does not stop.

  • public CoroutineAwaitable Until(Func<bool> predicate, ResumePoint? point = null)

    Waits until a predicate is true, testing it once per occurrence of the resume point.

  • public CoroutineAwaitable While(Func<bool> predicate, ResumePoint? point = null)

    Waits while a predicate is true.

  • public CoroutineAwaitable ResumeOnLoop(ResumePoint point = Update)

    Comes back to the loop thread after awaiting something that left it.

  • protected virtual void Awake()

    Called once, when the behaviour is attached, before anything else.

  • protected virtual void OnEnable()

    Called after Awake, and whenever the behaviour is enabled again.

  • protected virtual void Start()

    Called once, the frame after Awake, before the first Update.

  • protected virtual void Update()

    Called every frame in SystemPhase.Update, while enabled.

  • protected virtual void LateUpdate()

    Called every frame in SystemPhase.LateUpdate, while enabled.

  • protected virtual void OnDisable()

    Called when the behaviour is disabled, and before OnDestroy if it was enabled.

  • protected virtual void OnDestroy()

    Called once, when the behaviour or its entity is destroyed.

  • public ref T Get<T>()

    A reference to one of the entity's components, for writing.

  • public ref readonly T Read<T>()

    A reference to one of the entity's components, for reading.

  • public bool Has<T>()

    Whether the entity has a component.

  • public T? GetBehavior<T>() where T : Behavior

    Another behaviour on the same entity, if there is one.

  • public void Destroy()

    Destroys this behaviour, running OnDisable and OnDestroy at the next drain.

Used by (40)

  • CharacterAnimationThirdPersonShooter
  • LampFlickerThirdPersonShooter
  • RespawnWhenBelowThirdPersonShooter
  • SunOrbitThirdPersonShooter
  • WeaponFireThirdPersonShooter
  • BehaviorBucketVixen.Engine
  • BehaviorRefVixen.Engine
  • BehaviorStoreVixen.Engine
  • BehaviorTestsVixen.Engine.Tests
  • CoroutineTestsVixen.Engine.Tests
  • HoldsAResourceVixen.Engine.Tests
  • IBehaviorBucketVixen.Engine
  • ISceneBehaviorBinderVixen.Engine
  • MarkerVixen.Engine.Tests
  • MoverVixen.Engine.Tests
  • NestsACoroutineVixen.Engine.Tests
  • NetworkBehaviourVixen.Net.Engine
  • PatrolVixen.Engine.Tests
  • RecorderVixen.Engine.Tests
  • RegistrationTestCodeOnlyVixen.Engine.Tests
  • RegistrationTestWeaponVixen.Engine.Tests
  • SceneBehaviorBinderVixen.Engine
  • SceneBehaviorRegistryVixen.Engine
  • SceneManagerVixen.Engine
  • SequencerVixen.Engine.Tests
  • SpawnerVixen.Engine.Tests
  • StartsACoroutineVixen.Engine.Tests
  • Vixen_Engine_Tests_PatrolSerializerVixen.Engine.Tests
  • Vixen_Engine_Tests_RegistrationTestSwordSerializerVixen.Engine.Tests
  • WaitsTenSecondsVixen.Engine.Tests
  • BehaviorBridgeVixen.Editor.SceneView
  • EditorApplicationVixen.Editor.App
  • PatrolVixen.Editor.SceneView.Tests
  • PatrolBehaviorVixen.Editor.App.Tests
  • ProjectAssemblyTestsVixen.Editor.App.Tests
  • RecorderVixen.App.Tests
  • SceneSerializerVixen.Editor.SceneView
  • TypeRegistrationVixen.Editor.App.Tests
  • Vixen_Editor_App_Tests_PatrolBehaviorSerializerVixen.Editor.App.Tests
  • Vixen_Editor_SceneView_Tests_PatrolSerializerVixen.Editor.SceneView.Tests