playcanvas / playcanvas/engine
Changing the sprite resource on a sprite component doesn't cancel the initial asset load callback
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 16.8k
- Forks
- 2k
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 222
Description
Repro project: https://playcanvas.com/project/890457/overview
Forum: https://forum.playcanvas.com/t/changing-sprites-on-initialize-doesnt-work-properly-without-preload/24589
The sprite that is assigned in the Editor is not preloaded (Base Image) and there is a script attached to it that changes the sprite to one that is preloaded on init (Final Image).
What is expected is that the sprite component keeps showing the Final Image
What actually happens is that it shows the Final Image and then changes 'back' to the Base Image:
- On startup, the sprite component tries to use the Base Image that isn't preloaded. As it's not loaded, it triggers an asset load
- The script changes the sprite to use Final Image which is preloaded and renders it on the screen
- The Base Image asset finishes loading and triggers the callback to assign the Base Image sprite to the sprite component
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior with project 890457 and inspect the sprite component's handling of the unloaded Base Image and its asset-load callback. Verify the fix by changing to the preloaded Final Image during initialization and confirming that the later Base Image load does not replace it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100