‹
Utility Scripts

Custom Body Data

Associates project-owned gameplay information with every managed physics body.

Every high-level JoltBody exposes a public data variable containing an ordinary GML struct. It is intended for names, item properties, health, categories, inventories and other gameplay metadata that should travel with the body wrapper without becoming part of the native physics state.

Basic usage#

GML
body.data
options.data

Creation contract#

CaseBehaviour
No data optionThe new JoltBody receives its own independent empty struct {}.
data: {...}The supplied struct is assigned directly to body.data and is not cloned.
Non-struct dataBody creation fails with JOLT_ERROR_INVALID_ARGUMENT.
Later replacementbody.data may be replaced at any time with another struct by normal GML assignment.

Supported body creation paths#

  • Dynamic, Static and Kinematic primitive constructors accept options.data.
  • Bodies created from reusable JoltShape resources accept the same option.
  • Compound builder create, create_static and create_kinematic paths preserve custom data.
  • Each body created without explicit data gets a distinct container; editing one default struct cannot affect another body.

Reference and mutation semantics#

  • The supplied struct follows normal current GameMaker reference/value semantics. The extension does not deep-clone it.
  • Nested structs and arrays remain usable and mutable through body.data.
  • When the same struct is retained elsewhere, changes made through either reference are visible through the other according to normal GML semantics.
  • The extension does not validate individual fields because their schema belongs entirely to the game project.

Where the data remains available#

Result or systemAccess
Raycast and Shape QueriesRead hit.body.data from the returned registered JoltBody wrapper.
Collision and sensor eventsRead event.body_a.data and event.body_b.data.
ExplosionRead result.bodies[i].data or result.entries[i].body.data.
Object GrabberRead grabber.get_body().data while an eligible body is held.
Direct body referenceRead or edit body.data without a native bridge call.

body.data and user_data#

Featurebody.datauser_data
Intended valueA gameplay metadata struct with project-defined fields.Any caller-defined value, commonly an entity or GameMaker instance.
Creationoptions.data or a new independent {}.undefined until set_user_data() or bind_instance(..., true).
Query aliasAvailable through the returned body wrapper.Also exposed as entity or other_entity by several result/event APIs.
Native physicsNever sent to Jolt Physics or the bridge.The GML value is also wrapper-side; native Body UserData internally remains reserved for managed handles.

Lifecycle and ownership#

  • Destroying a body invalidates its physics handle but does not erase data from an old wrapper that GML still references.
  • A new body that reuses a native slot receives a new wrapper and new empty data; metadata never leaks from the destroyed body.
  • body.data does not change mass, collision, sensor state, velocity, sleeping or resource lifetime.
  • Save/load, JSON conversion, networking and persistence are project responsibilities and are not provided by this feature.

Example#

GML
var bottle = jolt_box_create_dynamic(0, 0, 3, 0.5, 0.5, 1, {
    mass: 1,
    data: {
        name: "Bottle",
        price: 20,
        health: 10,
        type: "item",
        inventory: ["Gold", "Potion"]
    }
});

show_debug_message(bottle.data.name);
bottle.data.health -= 5;
array_push(bottle.data.inventory, "Sword");

Verified operation contracts#

These contracts distinguish units, return values, errors and lifetime according to the current implementation. Check results: false, 0 and undefined can mean different things for different methods.

Symbol / ownerSignatureOperation contract
JoltBody.get_user_dataJoltBody.get_user_data()Any GML value, setter true/getter value; invisible to native. Separate data is also a pure GML struct, not physics configuration.
JoltBody.set_user_dataJoltBody.set_user_data(value)Any GML value, setter true/getter value; invisible to native. Separate data is also a pure GML struct, not physics configuration.