Hi, I have instantiated a template at runtime and I am trying to find the children of that instance (by name) )and tween them, but I just keep getting errors that they are undefined:
This part instantiates the entity and tries to assign its child entities (called Explode_Layer_0,Explode_Layer_1 etc)
if( modelAsset && modelAsset.loaded)
var instance = modelAsset.resource.instantiate();
//get cutaway layers. These models should now exist in the scene
But when I try to tween later like this they come back as undefined(Cannot read property ‘tween’ of undefined):
this.explodeLayer_1.tween(this.explodeLayer_1.getLocalPosition()).to(new pc.Vec3(0, this.offsetAmount, 0), this.tweenTime, pc.SineOut).start();
I triple checked and the the names of the entities are all correct and match with the names inside the template.
Have you tried searching directly on the instance, instead of root? That would be much faster as well:
I still get the same error.
Hmm, is there any chance the tween.js library is loaded after that code runs? Tweening works as expected with other entities?
Yeah, I already have tweening on other entities before this that works fine. It seems to be a problem with accessing the entity, for example even this code comes up wit the same error:
this.explodeLayer_1.name="some new name";
That implies that entity of the that name doesn’t exist. Any chance of sharing a build link or you can use my devtools to print out the hierarchy of the scene into the console (https://github.com/yaustar/yaustar.github.io/tree/master/playcanvas-devtools)
Okay I sent an invite. Sorry for the delay but I was putting out a fire (quite literally in my house! - all safe now). To see the error just run it and choose Purple> Purple Original (You’ll see what I mean.)
The script with the issue is called model-screen-manager.js
Looking at the scene, there isn’t any nodes named ‘Explode_Layer_0’ to ‘Explode_Layer_5’
As it’s the mattress that we are looking at:
No child entities are here in the scene with the template and no other graph nodes at runtime on the model
There’s only one mesh instance in the GLB
Importing the OBJ in Blender only shows one node too
Did you mean to instantiate ‘Test_Cutaway’ instead?
Yes!. Apologies I was looking at the wrong mattress all along! If you look at the Purple Hybrid 4 it works fine. Thanks for your help and apologies for being stupid with this one.