Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual Content: Document how to prevent "Automatically remove unused assets" when compiling #9011

Closed
gnysek opened this issue Jan 13, 2025 · 2 comments
Assignees
Labels
docs-bug GameMaker Manual Bugs
Milestone

Comments

@gnysek
Copy link
Contributor

gnysek commented Jan 13, 2025

Description

2024.11 added Automatically remove unused assets when compiling option for game.

However, sometimes assets are get using string concatenation, like asset_get_index($"spr_npc_{npc_id}"). This way they don't be included if they aren't used in any of objects/sequences/rooms. There's no description or hint how to solve it, while there are ways.

Best way to include them is to add line like this somewhere in code:

var _used_assets = [spr_npc_1, spr_npc_2, spr_npc_3, ...];

and best place for this seems to be global scope script outside of any function (so it's removed from memory after game initialise, and not recreated later).

However, I'm 99% sure, that asset compilation happens before compilation, and before compilation optimisation, which means safest way to do it should be:

if (false) {
   var _used_assets = [spr_npc_1, spr_npc_2, spr_npc_3, ...];
}

As this way Asset compiler would include those resources, but compilation optimisation would not include that part of code at all.

As 2024.13 will be also getting optimisation to include such resources by their tag/asset type (proposal is: gml_pragma("compile_asset_tag", ">tag>");, etc. - check #8313 for futher info), so my proposal could be added together with additional info about that new pragma, which could be also referenced/linked on Game Options page in manual:

Image

Manual Link

https://manual.gamemaker.io/beta/en/#t=Settings%2FGame_Options.htm

@gnysek gnysek added the docs-bug GameMaker Manual Bugs label Jan 13, 2025
@stuckie stuckie moved this from Triage to Backlog in Team Workload Jan 14, 2025
@stuckie stuckie marked this as a duplicate of #9031 Jan 16, 2025
@YYBartT YYBartT moved this from Backlog to In Progress in Team Workload Jan 27, 2025
YYBartT added a commit to YoYoGames/GameMaker-Manual that referenced this issue Jan 28, 2025
…scribe how to prevent

YoYoGames/GameMaker-Bugs#9011

* "MarkTagAsUsed" pragma already added on the Game Options page (in YoYoGames/GameMaker-Bugs#8313)
* Added a note on how referencing an asset only through asset_get_index() will cause it to be removed by the compiler and how to prevent using the "MarkTagAsUsed" pragma
* Added a second code example that shows how to use asset_get_index() in combination with the "MarkTagAsUsed" pragma
@YYBartT YYBartT added this to the 2024.13 milestone Jan 28, 2025
@YYBartT
Copy link

YYBartT commented Jan 28, 2025

The "MarkTagAsUsed" pragma was already added to the description of the game option in #8313. Added an extra note to the asset_get_index() manual page that explains that an asset is considered "unused" and will be removed by the compiler if it's only referenced through this function. Also added that the "MarkTagAsUsed" pragma can be used to prevent removal of such assets and a second code example showing its use.

@YYBartT YYBartT closed this as completed Jan 28, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Team Workload Jan 28, 2025
@YYBartT YYBartT moved this from Done to Ready for QA in Team Workload Jan 28, 2025
@mgeddesGM
Copy link

verified

@mgeddesGM mgeddesGM moved this from Ready for QA to Verified in Team Workload Jan 29, 2025
@YYDan YYDan changed the title Automatically remove unused assets when compiling - describe how to prevent Manual Content: Document how to prevent "Automatically remove unused assets" when compiling Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-bug GameMaker Manual Bugs
Projects
Status: Verified
Development

No branches or pull requests

4 participants