Table of contents

When Claude writes code for your game, you don’t have to understand every line, but you will often see the method names Awake, Start, and Update. Unity calls these methods for you at set moments: when an object appears, before the first frame of the game, and then on every frame. A frame is one picture the game draws, many times per second. Once you know this order, you can tell whether Claude put one-time setup and per-frame work in the right places, and when the game misbehaves, you know which part to ask Claude to check. Below, a small script that prints messages shows the order. You then compare it with the code of the Fruit Catcher game, and last you meet the attributes Unity 7 adds for running code when you enter and leave Play Mode. An attribute is a label in square brackets above a method that tells Unity how to treat it.
It comes after Unity 7 C# scripting basics, which creates your first script and explains why static values (values that belong to the class, not to one object) don’t reset on every Play. I tested on Windows 11 with Unity 7000.0.0a23 (Alpha, an early preview build), and defaults may still change before the stable release.
Check how scripts work in Unity 7
Unity 7 has no new way to write Start and Update. On the same computer, I created one “MonoBehaviour Script” in Unity 6000.6.10f1 and one in 7000.0.0a23. The two files are identical, and both match the template in the Unity 7 manual page on MonoBehaviour: a class that inherits from MonoBehaviour with empty Start and Update methods.
1using UnityEngine;
2
3public class NewMonoBehaviourScript : MonoBehaviour
4{
5 // Start is called once before the first execution of Update after the MonoBehaviour is created
6 void Start()
7 {
8
9 }
10
11 // Update is called once per frame
12 void Update()
13 {
14
15 }
16}
The Unity 7 manual page on event functions also still uses Start, Awake, and Update to explain initialization and per-frame updates. Scripts written for Unity 6 don’t need changes in this area.
Understand the execution order
From the moment an object appears until it goes away, the six most common methods run in a fixed order, and only Update repeats:
| Method | When it runs | What usually goes in it |
|---|---|---|
Awake |
Once, when the object loads | Get components on the object itself, such as a Rigidbody |
OnEnable |
Every time the object or component is enabled | Start receiving events, such as subscribing to input |
Start |
Once, before the first Update |
Setup that needs other objects to be ready, such as finding GameManager |
Update |
Once every frame | Read key presses, move objects, run timers |
OnDisable |
When the object or component is disabled or deleted, or Play stops | Stop receiving events |
OnDestroy |
When the object is deleted, or Play stops | Final cleanup |
Every object’s Awake in the scene finishes before the first Start runs (event functions manual). If you prepare the object itself in Awake and read other objects’ data in Start, you won’t read something that isn’t ready yet. The order of the same method across different objects is not fixed. For example, the basket’s Update doesn’t necessarily run before a fruit’s Update (execution order limits).
Watch the order in the Console
To check the order, ask Claude to write a script that prints a message in every method. Open your practice project in the Code tab of the Claude desktop app and enter:
1Create a LifecycleLogger script that uses Debug.Log to print the method name in Awake, OnEnable, Start, the first Update, OnDisable, and OnDestroy, and attach it to an empty GameObject in the scene.
After the script is attached, press the Play button, wait a few seconds, and press the Play button again to stop. The Console lists the methods in order. In my run, the lines were also numbered, such as “1 Awake”, and yours may be worded differently. My practice project also has a class named PlayModeHooks that prints a message from the attributes in the next section, so the first and last lines in the Console come from that class. You don’t need it for this exercise. The “Play count: 1” line in the middle comes from another script on the same object:

When two scripts are on the same object, there is no guarantee which Start runs first, so “Play count: 1” can appear before “3 Start” or after it.
When you finish the exercise, remove LifecycleLogger from the object or delete the script.
Compare with the Fruit Catcher code
The five scripts in the Fruit Catcher game follow the same division of work. Open Assets/Scripts in the Fruit Catcher project on GitHub. The table below summarizes what the scripts there do, and you can read the scripts themselves in the repository:
| Script | Methods used | What it does |
|---|---|---|
| BasketController | Start, Update, OnTriggerEnter | Finds the camera at the start, reads the arrow keys every frame to move the basket, adds points or removes a life on a catch |
| FruitSpawner | Update | Runs a timer, spawns a fruit when time is up, and shortens the interval every 15 seconds |
| FallingItem | Update | Deletes itself when it falls below the floor, and removes a life when a fruit is missed |
| GameManager | Start, Update | Sets the lives and updates the display at the start, and reads the R key to restart after Game Over |
| ScoreUI | (none) | Doesn’t run on its own; GameManager calls it to update the score and lives text |
OnTriggerEnter is also a method Unity calls for you. It runs only when something enters the basket’s trigger area, and it isn’t one of the six methods above. ScoreUI uses none of the methods Unity calls automatically, which means it acts only when other code calls it.
When the game misbehaves, this table helps you decide where to ask Claude to look. For example, if the score doesn’t go back to zero after a restart, ask Claude to check GameManager’s setup at the start. If the basket’s speed depends on how fast the computer is, ask Claude to check whether Update in BasketController multiplies by Time.deltaTime, the number of seconds the previous frame took, which keeps movement at the same speed on fast and slow computers.
Run code when entering and leaving Play Mode
Awake and Start belong to objects in the scene, and they don’t run if the object doesn’t exist. Some code has nothing to do with objects and only needs to run once each time you press Play or stop, such as resetting a static counter (a counter shared by the whole class) to zero. Unity 7 provides two attributes for this:
| Attribute | When it runs |
|---|---|
[OnEnteringPlayMode] |
When you enter Play Mode, and when a built game starts |
[OnExitingPlayMode] |
When you stop Play Mode, and when a built game quits |
You write these attributes on the line above a static method (a method that belongs to the class itself), and the class that holds the method doesn’t have to be attached to an object. Here is a static counter that resets to zero every time you stop Play Mode, based on the example in the Unity 7 manual (resetting static values):
1using UnityEngine;
2
3public static partial class PlayCounter
4{
5 public static int Count;
6
7 [OnExitingPlayMode]
8 static void ResetCount()
9 {
10 Count = 0;
11 }
12}
You must add partial to the class. partial is a C# keyword that lets one class be written in two pieces, and Unity generates the second piece for a class that uses these attributes. Without partial, the Console shows this compile error:
1PlayCounter.cs(8,17): error UAC0031: Lifecycle method 'PlayCounter.ResetCount()' must be declared in a partial type
With partial added, I pressed Play twice in a row. Each time, Count went from 0 to 1 during Play, and after I stopped, it went back to 0.
To do the same thing in Unity 6, you subscribe to EditorApplication.playModeStateChanged in the UnityEditor namespace (a named group of Unity code) and then check whether you are entering or leaving Play Mode. The Unity 7 manual recommends the attributes for new code. They live in the UnityEngine namespace and also run in a built game (lifecycle manual).
If you only want static fields to return to their initial values on every Play, [AutoStaticsCleanup], introduced in Unity 7 C# scripting basics, is simpler because you don’t write a reset method. Game data such as the score and lives belongs on the GameManager object instead of in static fields. Because the scene’s objects are created from the saved scene each time you press Play, that data starts from its initial values on every Play, and the CLAUDE.md of Fruit Catcher records the same rule.
The earlier Console output also shows when the two attributes run: [OnEnteringPlayMode] runs before any Awake in the scene, and [OnExitingPlayMode] runs after all OnDestroy calls.
Test notes
| Item | Details |
|---|---|
| System | Windows 11 physical machine |
| Editor | Unity 7000.0.0a23 (Alpha) |
| Compared with | Unity 6000.6.10f1 |
| Template | Universal 3D (com.unity.template.urp-blank) |
The files created with Create > Scripting > MonoBehaviour Script are byte-for-byte identical in both versions. A new Unity 7 project’s Enter Play Mode Settings don’t reload code by default, so static fields keep the value from the previous Play. Details are in Unity 7 C# scripting basics.
Summary
Script syntax is unchanged in Unity 7, and once you know what Awake, Start, and Update are for, you can tell whether Claude’s code is in the right place. What Unity 7 adds is the pair of attributes that run when you enter and leave Play Mode, and you need them only when the code has nothing to do with scene objects.

