Can't create node from group ready


#1

Have the following code:

let myobj = Z.Object();
myobj.type(“Plane”);
myobj.skin(symbol.mediaFiles.icon_png);
symbol.nodes.Group.push(myobj);

If you put it inside parent.on("show", () => {});(the script right below root) it works fine. However, if you right-click the group and create a new ready script: parent.on("ready", () => {}); and put the same code there, ZapWorks Studio will get stuck on unlocking forever. If you add a console.log("why?") you will notice the code gets executed in an infinite loop, removing the line myobj.skin line fixes the bug but then the plane won’t show because the skin got removed. This is quite…strange.


#2

Setting a skin will set a node to “notready”. If it’s just a standard texture from the media file list that is already loaded then it will simply be reported “ready” again in the next frame, whereas if its a URL that needs downloading that may take longer.

So setting a skin in an on(“ready”) may indeed lead to an infinite loop. You could just use parent.one("ready") so it is only fired once, or even just have your code lose in a script node so it runs as the scene is loaded.


#3

Oh, interesting. Thanks Simon, I will keep that in mind if something similar happens again.