Instantiate Templates

Hey,

Those templates might be some sort of reference, and if not I also do not see any reason for that to occur. You want to instantiate the templates without the hierarchy, and I have done this already and I would suggest a couple ways.

  1. Create an attribute to store the specific template you wanna create
    In order to do this way, just make an attribute that has:
ScriptName.attributes.add('chhesTemplate', {
    type: 'asset',
    assetType: 'template'
});

After making that attribute (in a script) you can call the following code (either in the initialize function OR update, or wherever you need it):

var instance = this.chhesTemplate.resource.instantiate(); //this CREATES it and stores in a variable

You may use this variable as you please, because it stores the instance of the template

  1. You can also just find the asset’s ID and paste this into the .get()

Example:
Let’s say your asset’s ID (listed AT THE TOP of the template’s description, NOT the entity, the actual template asset) is 551247. This is just an example, but lets say it is this.

By using the following code, you can find the template asset and then create another instance of it

var templateAsset = this.app.assets.get(551247);
var instance = templateAsset.resource.instantiate();

I hope this helps!!

Chhes :cheese:

5 Likes