How often does "ready" event fire?


#1

I have the following initialization code in a script at the root of the hierarchy…

export const MAX_EMITTERS = 15;

parent.one("ready", () => {

	// Allocate a pool of emitters to be used in touch events.
	for ( let i = 0; i < MAX_EMITTERS; i++ ) {

		// Instantiate particle emitter
		let emitter : any = Z.Symbol("Particle Emitter");
		emitter.nodes.Code.init(); // required

		// Add to hierarchy so it's visible when activated.
		symbol.nodes.Touch_Emitters.push( emitter );		
	}
});

Initially, I used on() to handle the event, but the experience would be unresponsive as soon as it launched and the camera feed very sluggish as though the app was compute-bound. After changing the method to one(), it works fine.

I couldn’t find any documentation specifically on the ready event, but the above suggests that it was firing repeatedly, thereby causing my initialization loop to run continuously and hog resources.

I’m just guessing about that, of course, so can anyone at Zappar shed light on exactly when the ready event fires and whether it’s just once per experience?

Things are working now, but this would be good to know for future reference.


#2

Hi @shot,

The ready event is emitted when an object (or a child object) is loaded and is ready to be used. Dynamically creating symbols within the on('ready') block creates an infinite loop of object creation, thus creating the resource hog you’re experiencing.

I have passed your documentation request over to our technical documentation team.

All the best,
Deim


#3

Aha! The “or child object” part explains it! That certainly wasn’t clear. Thanks so much for the reply. This will come in handy in the future.