I’m working on a project with templates. When I load a template into scene all is fine. Next i try get and edit children entity. And i can`t do, because like template is protected(i guess).
Also I have a version that I’m doing something wrong, because I’m new here (playcanvas).
Main question: how i can edit entity inside template in runtime by script?
Thanks very much!
Are you trying to modify the template asset or the template instance that is in the scene?
Template instance that is in the scene.
From the moment you instantiate a template, it becomes a regular pc.Entity.
That means you can edit it in the same way you would edit any entity:
var entity = templateAsset.resource.instantiate();
entity.findByName('Entity_1').name = 'Entity1');
Yes you have a right, I can edit name of entity, but I can`t edit model like:
1)when i do findByTag something wrong. Name is changes but model… not.
2)when i do findByName all work, but this pipeline is not comfortable.
Are you certain the entity has tags? In the code above you aren’t adding/editing any tag on the entity, only the name.
Also what do you mean by … name changes but model… not?
Would you be able to provide a small reproducible project if possible? It can help us give a solution that would work for you
@Leonidas Yes, the entity has tags.
I mean data of entity:
I also do not rule out that I am somewhere technically wrong.
The material change looks like it is working to me (Glass to plastic when changing to M sized bottle)
Bear in mind that https://developer.playcanvas.com/en/api/pc.ModelComponent.html#material is not used for model components of type assets.
I’m looking into the tag issue now
findByTag returns an array as there could be more than one entity with the tag: https://developer.playcanvas.com/en/api/pc.Entity.html#findByTag
So the code would be:
var entity_1 = this.entity.findByTag("Bottle");
@yaustar thx. My problem is SOLVED