☑ Instantiate an entity in runtime

Hello Team,

How can I instantiate an entity in runtime which is there already in hierarchy…?

http://developer.playcanvas.com/en/tutorials/intermediate/using-assets/

Well, that tutorial is more about assets than entities, @Dinkelborg_At_C4Real. I’d probably recommend looking at this one:

http://developer.playcanvas.com/en/tutorials/intermediate/procedural-levels/

It clones a ‘house’ entity in the hierarchy and makes many copies (using the pc.Entity#clone function).

Hi,
A method that has worked quite well for me is to create a place in the hierarchy to store the models I would like to create at runtime.
For example PreFabs and then disable it so that it doesn’t show any of the entities underneath it.

Then in scripts I can use:

var entity = this.app.root.findByName('NameOfEntity');
var newEntity = entity.clone();
app.root.addChild(newEntity);

Thanks all for the help :slight_smile: