Hello,
I instantiate a template by code. The first instance has all the tags the original asset has. From the second instance on, all tags are lost. When trying to add the missing tags manually by code, it doesn’t work too. My question:
- has anyone experienced and solved that problem?
- instance.tags.add(“interactive”,“pickable”); doesn’t add the tags.
that’s my code:
var templateAsset = this.app.assets.get(54317203); // box with tags: "interactive","pickable"
var instance = templateAsset.resource.instantiate();
this.TargetRoot.addChild(instance);
console.log("num of tags " + instance.tags.length); <-- it is always undefined
console.log("first tag " + instance.tags[0]); <-- it is always undefined
Am I missing something here?
Best Christof
Hi @ChrisPohl,
To get an array list of an asset or entity in this case you need to call a method (pc.Tags is an object).
Try doing this:
const tags = instance.tags.list();
Thanks Leonidas,
but it seems not to work. tags.add says there is no add function. Any other ideas? What makes me wonder is, why do I have to retag the entities anyway. An instance of a template should have all attributes of the original, right? Losing tags seems more like a bug to me.
An instance of a template is an entity so tags.add should definitely work the least.
Are you able to share a sample project to take a look?
Just tried this in a new project. Looks fine when using the tags API:
Project: https://playcanvas.com/editor/scene/1221725
// initialize code called once per entity
Test.prototype.initialize = function() {
var templateAsset = this.app.assets.find('Box', 'template');
var instance = templateAsset.resource.instantiate();
this.entity.addChild(instance);
console.log("num of tags " + instance.tags.size);
console.log("first tag " + instance.tags.list()[0]);
instance.translate(2, 0, 0);
};
1 Like
Hello yaustar,
Thanks for your example. The tags seem to work now. I want to “destroy” all entities that are tagged with a certain tag. But i did a mistake somewhere. It’s a private project so i have to recreate the error in a new public project what will take some time.
Best Christof