Skip to content

Interacting with game objects

Archie_UwU edited this page Sep 11, 2025 · 1 revision

Important

You are viewing documentation for C#.
To view the C++ article, click here.

Types of game objects

In C#, there are 4 main types of managed objects you may encounter. Each one corresponds to a native GameMaker type. The mapping can be seen in the table below:

C# type C++ Type Description
GameVariable RValue Describes a GameMaker variable.
GameObject YYObjectBase Describes a generic struct, sequence, instance or accessor object.
GameInstance CInstance Describes an instance of a GameMaker object.
GameRoom CRoom Describes a room.

GameVariable

This is the all-encapsulating type of GameMaker, similar to the C# object. It can contain any data supported by GameMaker itself - this means that one GameVariable object might contain a number, while another contains a string, all under the same type.

Creating a GameVariable

Being essentially just a boxed type, GameVariable can be instantiated from many C# types. It can then be implicitely converted back into those types.

If the conversion is invalid (such as trying to convert a string variable to a C# int, an InvalidCastException is thrown. This also holds true for all of the To* conversion functions.

If a GameVariable isn't assigned a value, it's initialized as undefined.

Type casting (Type property)

In order to check what underlying type a GameVariable holds, code can query the GameVariable.Type property of the target object. This property holds one of the following strings:

C# native type Type property value
double number
string string
IReadOnlyList<GameVariable> array
long ptr, int64
N/A undefined
GameObject / GameInstance struct / method
bool bool

Mutating nested types

Some types (such as structs or arrays) cannot have a reference to them outside of GameMaker, as their lifetime is not controlled by the C# runtime. This makes it impossible to obtain a "live" reference to both arrays and structs.

Due to this fact, there is no ToArray() or ToDictionary() function - instead, a read-only view of the contained array is returned by ToArrayView(). To atomically mutate members of an array, use the operator[int] indexer. Similarly to this, structs may have their members enumerated by looking at the Members read-only list of GameObject / GameInstance, but changes will only be reflected when using operator[string]. The same behavior also applies to GameVariable holding a struct.

Clone this wiki locally