OnEnteringPlayModeAttribute
Marks a static method as a callback to be invoked when entering Play mode.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]public sealed class OnEnteringPlayModeAttribute : LifecycleAttributeBase
Remarks
Methods marked with this attribute are called when entering Play mode. This happens:
- When starting Play mode in the Editor.
- When starting the Player application.
- After code reload in Play mode (Editor only).
Use this callback to:
- Initialize Play mode systems and game state.
- Set up Play mode data structures.
- Prepare runtime systems.
This is a method attribute that can only be applied to methods with no parameters and return type .
staticvoidAdditional Resources: OnExitingPlayModeAttribute, RuntimeInitializeOnLoadMethodAttribute, AfterManagedObjectsRestoredAttribute.
Examples
using UnityEngine;public static partial class PlayModeManager{ [OnEnteringPlayMode] static void OnPlayModeEntered() { Debug.Log("Entered Play mode"); }}
Constructors
Constructor | Description |
|---|---|
| OnEnteringPlayModeAttribute() | Marks the decorated static method to be invoked when entering Play mode. |