Variables are basic tools that help you create lively, interactive content by storing and changing data in different parts of your world.
Why use variables?
- Global: Share data everywhere.
- Player: Personalize experiences.
- Object: Control individual items or characters.
- Global Variables
- What they do: Hold data that can be used everywhere in your project (in all scenes, objects, or for all players).
- Examples:
- Track settings like game difficulty.
- Count things like total coins all players collect.
- Control states like game start or game over.
- Where they work: Available everywhere, even in multiplayer games for all players.
- Note: By default, global variables won’t update for other players unless you turn on the “Sync Variable” option.
- Player Variables
- What they do: Store data for one player only, so each player has their own experience.
- Examples:
- Track stats like health or score for each player.
- Manage items in a player’s inventory.
- Where they work: Only for the player they belong to, saved during their playtime. Perfect for multiplayer games to keep data separate.
- Object Variables
- What they do: Attach data to specific objects (like items, doors, or characters) to control how they behave.
- Examples:
- Set if a door is locked or open.
- Adjust physics settings like speed or weight.
- Where they work: Only affect the object they’re attached to. Lets you reuse the same object design with different traits.