Changing sprites on initialize doesn't work properly without preload

Hi guys!

We have entities with sprites components and we load the assets on a custom load screen. We put the sprites on initialize and we hope to visualize the final sprites. But we visualize the base sprites placed on editor.

I guess it happens because the editor calls to load the asset on initialize. And when the asset is loaded, it is placed as a sprite in the component.

We have duplicated the assets and exclude from build, but it is a tedious process. I don’t see any event called before initialize or before the load start to setup properties.

Example

Actually, the issue was that you had changed the script attribute name from ‘finalSprite’ to ‘finalImage’ but not parsed the script

Parse the script, re-add the asset to the script and it will work fine:
https://playcanvas.com/editor/scene/1350105

If you do a lot of this, I would recommend either not having a sprite asset in the sprite component to begin with, or use a placeholder sprite that is preloaded.

Really depends on the use case

1 Like

Ops, sorry, the hurry :sweat_smile:

Now is parsed, but still happening.

We have many worlds and we only load one world assets. In editor we have placed world1 assets. But in runtime we can load different worlds. We don’t need world1 assets.

If you can provide a reproducible project, that would really help here

In your example can see base image as final result.

Right, I see what’s happening here.

In which case, why not leave the sprite component blank to begin with? Or is the issue that it makes it hard to visualise in the Editor?

That’s exactly what happens, There are many elements and it is difficult for the game designer to work with the scene.

For a workaround, I would use the second method mentioned here

You can use a small texture atlas that has multiple colours for sprites.

This way, you don’t force an uneeded asset load when the scene is launched

Created ticket for this issue: https://github.com/playcanvas/engine/issues/4083

1 Like