Concept Flow - Creating and naming GameObjects
Start
Create GameObject
Assign Name
Use GameObject in Scene
End
This flow shows how to create a new GameObject and give it a name before using it in the scene.
GameObject myObject = new GameObject();
myObject.name = "Player";
Debug.Log(myObject.name);| Step | Action | GameObject Created | Name Assigned | Output |
|---|---|---|---|---|
| 1 | Create new GameObject with default constructor | Yes | Empty string | |
| 2 | Assign name "Player" to GameObject | Yes | Player | |
| 3 | Print GameObject name | Yes | Player | Player |
| 4 | End of code | Yes | Player | Execution stops |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| myObject | null | GameObject instance (unnamed) | GameObject instance named "Player" | GameObject instance named "Player" |
Create a GameObject with: GameObject obj = new GameObject(); Assign a name: obj.name = "NameHere"; Use Debug.Log(obj.name) to print the name. New GameObjects start unnamed. Naming helps identify objects in the scene.