public sealed class PlayModeControllerPlay, pause, step and stop, with the scene put back exactly as it was.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
In-process, which is the default of doc 11's two topologies. The game runs in the viewport against the world the editor was editing, and a snapshot taken on entry is restored on exit. What makes that affordable is the ECS layout — WorldSnapshot says how — and what makes it correct is that the restore clears first, so nothing a script created survives.
The hazard is state that is not in the world. A static field, a native allocation, a subscription to an event that outlives the session: none of them are in a snapshot and all of them make the second play-through behave differently from the first. Doc 11's answer is that a play-stop which leaks should fail rather than degrade silently, so the tracked-object count is compared across the session and Leaks is what it found. A test asserts it is empty; the editor shows it as a notification.
⚠ The selection is translated, not kept. Every entity gets a new handle on restore. The controller does the translation for whatever it was handed, because a caller that forgot would have a selection naming whatever landed in those slots — which looks like a rendering fault and is not one.
Fields and properties (4)
Events (2)
public Action<PlayModeController, PlayState>? StateChangedRaised when the state changes.
public Action<PlayModeController, IReadOnlyDictionary<Entity, Entity>>? RestoredRaised after a stop, with the table that translates old entities into new ones.
Methods (8)
public PlayModeController(World world)Drives play mode over a world.
public bool Play()Enters play mode, taking a snapshot first.
public IReadOnlyList<Entity> Stop(IEnumerable<Entity>? selection = null)Stops the game and puts the scene back.
public bool Pause()Stops stepping without leaving play mode.
public bool Resume()Starts stepping again.
public void Step(int frames = 1)Runs a number of frames while paused.
public bool ShouldTick()Whether the game loop should run this frame, and consumes a step if it does.
public void Dispose()Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Used by (3)
- EditorApplicationVixen.Editor.App
- SceneDocumentTestsVixen.Editor.SceneView.Tests
- SceneTestsVixen.Editor.SceneView.Tests