get_or_add

function

get_or_add(_uniqueName, _onAdd)

Description

Retrieves a reference to a resource. If the resource does not exist yet, then it is added.

Arguments

Name Type Description
_uniqueName String The name of the resource. Must be unique!
_onAdd Function A function which creates the resource if it does not exist yet. Must take no arguments and must return the created resource.

Example

Following code shows Create event of an object, where it assings its material using this method. When the first instance is created, it creates the material and adds it to the resource manager. When other instances are created, the material already exists and so they only get a reference to it.

/// @desc Create event
material = resourceManager.get_or_add("material", function () {
    var _mat = BBMOD_MATERIAL_DEFAULT.clone();
    _mat.BaseOpacity = sprite_get_texture(SprBaseOpacity, 0);
    return _mat;
});
Do you find this page helpful?

Copyright © 2022, BlueBurn. Built on May 16, 2022 using GMDoc.