Body State

Binding and Lifecycle

Reference and usage: Binding and Lifecycle.

APIContract
body.bind_instance(instance, use_as_user_data=true)Associates a live GameMaker instance; optionally uses its ID as user data.
body.sync()Copies position into owner x/y/z and quaternion into jolt_rotation_x/y/z/w.
body.unbind_instance()Removes binding without destroying the body or instance.
body.destroy()Releases the managed physics body; GameMaker instance lifetime stays caller-owned.
GML
// Create event of the visual instance, after physics has started.
body = jolt_box_create_dynamic(x, y, 2, 1, 1, 1);
if (!is_undefined(body)) body.bind_instance(id);

// After the central physics update, if an explicit sync is needed:
if (!is_undefined(body) && body.is_valid()) body.sync();

// Cleanup event:
if (!is_undefined(body)) body.destroy();

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.bind_instanceJoltBody.bind_instance(instance, use_as_user_data = true)Bind a live instance, use_as_user_data defaults true; Boolean. Unbind true, does not erase user_data or destroy the instance. Binding does not transfer lifetime ownership.
JoltBody.destroyJoltBody.destroy()Boolean, repeated calls true. Removes native body, attached sensors/helpers and connections; invalidates dependent constraints/vehicles/conveyors/scales. Does not destroy the bound GameMaker instance.
JoltBody.get_native_handleJoltBody.get_native_handle()Stored body/world handle when valid, otherwise 0. Do not retain across destroy or world restart.
JoltBody.is_validJoltBody.is_valid()Boolean valid flag + handle>0 + managed world started. Not a fresh native handle check; operations additionally validate world membership.
JoltBody.syncJoltBody.sync()Boolean; writes x/y/z and jolt_rotation_x/y/z/w into the bound instance. Requires a live binding; does not automatically render.
JoltBody.unbind_instanceJoltBody.unbind_instance()Bind a live instance, use_as_user_data defaults true; Boolean. Unbind true, does not erase user_data or destroy the instance. Binding does not transfer lifetime ownership.