Returns the unique index of the game asset with the given name.


GML Code Example


Argument Description
name The name of the game asset to get the index of (a string).

Returns: Real


You can use this function to get the unique identifying index for a game asset from its name. If the asset is not found, the function will return a value of -1, otherwise it will return the unique index id for the asset being checked. This id can then be used in other functions as you would any other index value, like the sprite_index or the path_index, for example. Please note that although this function can be used to reference assets from strings (see example below) you should always make sure that the asset exists before using it otherwise you may get errors that will crash your game.

NOTE: Script names will not resolve as assets on the HTML5 target platform due to obfuscation of the final code, which may cause issues and should be taken into consideration when using the function.


GML Code Example

var obj = asset_get_index("obj_Enemy_" + string(global.Level));
 if obj > -1
    instance_create(random(room_width), random(room_height), obj);

The above code will get an object index from a string, and if that index exists, create an instance of the object in the game.

No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here