EditorPlayModeSync

Synchronizes Play Mode enter/exit across multiple Unity Editor instances on the local network. Uses UDP broadcast on port 8052 to propagate state changes, enabling multi-instance testing workflows.

Definition

Namespace: Paragon.Core.Editor Assembly: Paragon.Editor.dll

[InitializeOnLoad]
public class EditorPlayModeSync : IDisposable

Attributes: [InitializeOnLoad] — initializes via static constructor on editor load. Implements: IDisposable

Remarks

This utility is designed for multi-editor workflows where you need multiple Unity instances to enter or exit Play Mode simultaneously (e.g., testing networked multiplayer locally).

Initialization Flow

  1. Static constructor runs on editor load ([InitializeOnLoad])

  2. Resolves the project name via ParagonPaths.Project for self-identification

  3. Subscribes to EditorApplication.playModeStateChanged to broadcast state changes

  4. Subscribes to EditorApplication.update to process received messages

  5. Creates a UDP client bound to port 8052 with broadcast enabled

Message Protocol

Messages are plain ASCII strings in the format: {clientName}:{PlayModeStateChange}

Message
Meaning

ProjectA:EnteredPlayMode

Project A entered Play Mode

ProjectA:ExitingPlayMode

Project A is exiting Play Mode

Self-Filtering

Each editor identifies itself by its project name (ParagonPaths.Project). When a message is received with a matching client name, it is ignored to prevent feedback loops.

Delayed Execution

Play mode transitions triggered by remote messages are delayed by 1 second via Yield.WaitForEditorSeconds to ensure stable state before transitioning.

Quick Lookup

Goal
How

Enable enter-play sync

Set EditorPlayModeSync.SyncEnterPlay = true in Editor Preferences

Enable exit-play sync

Set EditorPlayModeSync.SyncExitPlay = true in Editor Preferences

Disable all syncing

Set both SyncEnterPlay and SyncExitPlay to false

UDP port

8052 (hardcoded)

Message format

{clientName}:{PlayModeStateChange}

Properties

Property
Type
Access
Description

SyncEnterPlay

bool

public static

When true, entering Play Mode in another editor triggers enter here. Persisted via [EditorPreference].

SyncExitPlay

bool

public static

When true, exiting Play Mode in another editor triggers exit here. Persisted via [EditorPreference].

Fields

Field
Type
Access
Description

port

int

private const

UDP broadcast port (8052)

udpClient

UdpClient

private static

The UDP client for sending and receiving broadcasts

clientName

string

private static readonly

This editor's project name for self-identification

syncedPlayMode

PlayModeStateChange?

private static

Queued play mode change received from another editor

Methods

Connect (private static)

Creates and binds the UdpClient to port 8052 with ReuseAddress and EnableBroadcast, then begins async receive.

Broadcast (private static)

Sends a UDP broadcast message. No-ops if both sync preferences are disabled.

ReceiveCallback (private static)

Async callback for UdpClient.BeginReceive. Decodes the message and passes to OnMessageReceived, then re-registers for the next receive.

OnMessageReceived (private static)

Parses the {clientName}:{state} message. Ignores messages from self. Sets syncedPlayMode for processing in the next Update.

Update (private static)

Called every editor frame via EditorApplication.update. If syncedPlayMode is set:

  • ExitingPlayMode + SyncExitPlay enabled + currently playing → exit play mode after 1s

  • EnteredPlayMode + SyncEnterPlay enabled + not playing → enter play mode after 1s

Disconnect (private static)

Closes and nullifies the UDP client.

IDisposable.Dispose (explicit)

Calls Disconnect() to clean up the UDP client.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated