Components missing when instantiating template

I have a template object which has two scripts attached to it. When I create an instance of this template, the scripts are no longer attached.

It seems like the only component that is included is the render component. There should be collision and rigid body components as well.

TargetSpawner.prototype.postInitialize = function() {
    this.targetTemplate.ready(() => {
        this.spawnTarget();
    });
    this.app.assets.load(this.targetTemplate);
};

TargetSpawner.prototype.spawnTarget = function() {
    var newTarget = this.targetTemplate.resource.instantiate();
    newTarget.enabled = true;
    this.app.root.addChild(newTarget);
    console.log(newTarget);
};

Here is a screenshot of the template object properties

And here is the console output of newTarget from the code above

image

Is this how templates are supposed to work or am I missing something?

Hi @dgreenheck and welcome!

Did you apply the changes to the template after adding the scripts?

Yes, the instance I am editing says there are currently no overrides, which I take to mean all changes are applied.

image

What is the name of the template entity? Target or Cylinder?

The template is named “Target”. I see what you are pointing out, that the console log says the object name is “Cylinder”.

It turns out my TargetSpawner script wasn’t pointing to the actual template but something else. :man_facepalming:t2:

Sometimes it takes a second pair of eyes. Thank you!

1 Like