Quick answer: GameMaker arrays shared between variables despite assignment? GM 2.3+ copies the top-level array by value, but nested arrays / structs are still shared references — mutations leak.

var b = a; b[0][0] = 99; changes a[0][0] too. The outer array copied but the inner array is still the same reference.

Top vs Nested

GM’s value-semantic copy is shallow for one level. For a 2D array, the outer row vector is copied; the inner rows are shared. Mutate any inner element and both names see the change.

Manual Deep Copy

function deep_copy(arr) {
    var n = array_length(arr);
    var result = array_create(n);
    for (var i = 0; i < n; i++)
        result[i] = is_array(arr[i]) ? deep_copy(arr[i]) : arr[i];
    return result;
}

Recursive copy clones every level. Cost scales with size; use only when you need real independence.

Structs Same Issue

Struct assignment is reference too. b = a; on a struct shares all the same nested data. Use struct_copy (in newer GM) or hand-copy fields.

Avoid Hot-Path Copies

Per-frame deep copies are expensive. Restructure to mutate in place when possible — e.g. pass an index or a callback into the original instead of copying the whole structure.

Verifying

Mutating a copy doesn’t affect the source at any depth. Structs / nested arrays behave as independent values.

“GM copy is shallow. For deep independence, write a recursive copy.”

Adopt one convention (always copy in, mutate, return) — mixed semantics is the worst of both worlds.