Skip to content
Welcome to Spicy Pixel Answers, where you can ask questions and receive answers from the support team and other members of the community.

Is Spicy Pixel compatible with Unity JS ?

0 votes

Good morning,

I'm currently doing a browser gallery in JS and the problem is that some operations like :

  • Sprite.Create()
  • (UI.Image).sprite=mySprite

Are eating all the CPU and freeze the app during a few seconds (using coroutines).

In this context, is this possible to use Spicy Pixel ?

Thanks in advance for your help !


asked Sep 2, 2016 in Concurrency Kit by rattle-snake (150 points)

1 Answer

0 votes
Best answer
The Concurrency Kit works with Unity JS, but only the "fiber" and "coroutine" features are supported which won't help you here. JS doesn't support .NET threads which the rest of the kit is based on. JS uses web workers or threading.

That said, Unity is designed so that you can only interact with its objects on the main Unity thread. So the code you've written there can't be offloaded to another thread. I don't know why Unity didn't provide async methods for these kinds of long running operations.

Are you creating multiple sprites in a loop? If so, just yield between each iteration and you may not see the pause.

Depending on your scenario, you may also consider whether you can pre-load the sprites at scene setup when the user may already be waiting for the scene to load.

A related option would be to create a pool of sprites on scene load, and then reuse them throughout your scene playback, acquiring and releasing instances back to the pool as you need them. That way you may spend time updating a texture but not recreating the Sprite instance.

Creating objects in Unity is expensive, so try to pool as much as possible.
answered Sep 2, 2016 by admin (2,500 points)
selected Nov 5, 2016 by admin