How do I detect when my script's own model asset is loaded?

I have a script which make some changes to its own entity’s material and such, however the script doesnt seem to work on models that are not preloaded. (It works only if the model is ready at the start)

Although Im handling the preloading elsewhere, how can I get the script to run the rest of its calculations ONLY when its own models and materials have been loaded?

I think that the initialize function is running even when the model or material of itself isnt yet ready. Is that correct?

Hi @Grimmy,

You can use the asset list loader class to wait for a number of assets, that you need to find and list, and execute a callback as soon as all have finished loading:

Ooh great, it sounds very complicated though.Do you know how I could create a list of a scripts ‘own’ assets without actually knowing the assets manually by name beforehand? I want to be able to ad my script to any entity and it should work without having to know what material/model assets it uses.

I don’t think a script has assets right? Unless you reference them in script attributes, in that case you will know which properties are of type: “asset”. These will be the ones you need to include in your asset list loader.

I don’t think there is an easier way, but to be honest I don’t think it’s complex or hard either. Finding the assets you need to load, that’s something you need to work out case by case, and it’s not easy.

There isn’t a straightforward way to go from model → materials → textures right now.

1 Like