Unable to parse my script. UnCaughtError: Script Error

I am trying to create a script to insert entities at runtime to a specific model. When I tried parsing it it gave me a script error. I deleted things one by one to find out the source of the error. Here is my script.

var InsertEntityIntoPicture = pc.createScript('insertEntityIntoPicture');

var mainModel = this;
var entity = new pc.Entity();


// this.app.root.addChild(entity);
// initialize code called once per entity
InsertEntityIntoPicture.prototype.initialize = function() {
    // this.app.root.addChild(entity);

InsertEntityIntoPicture.prototype.onKeyboardPress = function(event){

I found out that the error is due to the line 


Is this the correct way?? Or is there some other way to do it??

What exactly are you trying to do?

Consider I already have a car in my scene without doors. I want to implement a function that puts on the doors on the press of a button.

Basically, the door would be an asset that I have already uploaded. I want it to appear in my scene at runtime

Keep them there all the time, just set visibility to false. Then on the button bring clicked, set the visibility to true and you’re done.

Hope that helps @Vishesh_Chanana

That was an alternate solution I was thinking. I was just wondering if putting all the models in the scene from start might increase the time taken to load.

Why don’t you try? It shouldn’t take too long

I’ve done it before myself

yeah, I’ll try this…

Thanks. I was able to do that.
But there is still an error that I am facing. I have a model which has sub models. When I try to apply the script to the whole model as whole, the model does not hide but when I apply the same script to a single element inside the model, the particular element hides.

How can I correct that.

Find the children using var //variableName = this.app.root.findByName(//model name)

Then apply the visibility program to the children :grinning:

Send me the link to your project

And give me access to it

I cant give you access to the project. Client does not allow

Send the link anyway

I’ll help you that way

I guess I got that working

It’s not loading on mobile, I’ll try it on my laptop later

Cool, it works :grin: