Templates - Can't apply Position/Rotation

Hey hey, we are now starting to use templates in our project and I noticed some behaviour which I’m not sure is intended. When creating a new template by right clicking on an entity, it’s current configuration is stored in the template. This includes local position and local rotation. But when I move the entity or adjust said properties, I don’t get the option to apply it to the template and I don’t quite understand the reason why. Or is this simply a bug?

Example: We want to place multiple coins in our scene. When we created the template, the coin we used was not at the origin. Let’s say its local position was (0, 5, 0). Now everytime I’m placing a new coin beneath any entity, I need adjust the height, since I can’t just set the default local position of the coin to (0, 1, 0).

Please help me understand this :slight_smile:

@vaios Does the Entity transform get ignored for applying back to the Templates? If they are ignored, could we change the Template position/rotation directly?

I believe that you cannot apply the position of a template instance back to the template because it’s expected that when you place a template instance in a scene you will adjust its position and rotation.

Maybe the Template assets so be set at 0, 0, 0 and identity rotation when they are first created? Or when they are added to the scene in the Editor, it will be set at origin? That way, at least it’s consistent where they appear.

Kinda hard to tell from your description.

I started today with templates and I am in luv :smiling_face_with_three_hearts:

Maybe this code gets you going:

            // this.template == scriptattribute >> 
            // Script.attributes.add('template', { type: 'asset', assetType: 'template' });
            var instance = this.template.resource.instantiate(); 
            // Inset your x,y here
            var pos = new pc.Vec3(x , y, 0);
            // Attach to Entity 

Thanks for the quick replies

@Sebastian I’m not having trouble setting the position in my scripts, but when I change properties of an instantiated template in the editor. The editor usually marks that property in a light blue and i can apply that change to all instances of that template if I want to. But thats not possible for position and rotations

@vaios Yeah, thats what I figured as well. Usually you set the position of the instance right after creating it anyway. It’s just a bit inconvenient, that the template stores the local offset of where it was created, but I have no way of resetting that offset. I would expect that template instances are either spawned at local position (0, 0, 0), or I can apply a new offset to the template. same for rotation.

@yaustar I don’t know if I would like to have the template always spawn at (0,0,0) with an rotation of (0,0,0). When I create a template, I might want to create a default orientation/offset. I would prefer if I could just apply these properties to the template like I can do with all other properties.

It also confused me a bit that it works different for the scale of the entity. I CAN apply a scale to the template. So part of the transform can be set, and other parts can’t.

Yeah the thinking was that position and rotation are very likely to be modified for every template instance so if for example you placed 3 instances in different positions and you changed some other component property in one of them and clicked Apply All, then that wouldn’t mess with the positions / rotations of the other instances.

Scale on the other hand is probably a bit more permanent so that’s why we let that be an override.

We might have to rethink the position / rotations though so that you could maybe apply them to the template and then only instances who had the previous default template position / rotation are updated while the others remain in place.

Spawn at a local position does sound a lot better than spawning at world position :thinking:

Is it an offset problem? I think you can just parent the coin to an empty object and make the parent as the template instead of the coin itself.

@guzu True, but that would only be a work around. The issue in my eyes is that all property changes can be applied to the template except the position and rotation, which seems inconsistent.

If you are setting the position after instantiating, you are overriding the position anyway.

Any updates on this? We just ran into the same problem where we tried instantiating templates, only to find out they were positioned/rotated wrong. We had assumed that templates were saved with zeroed transforms. As it is now, a template’s transforms are saved on creation, but can’t be edited after-the-fact. If we want to zero a template’s transform, we have to remove the old template and create an entirely new asset (which would break already placed templates).

Here’s an example of our usecase. We need to instantiate a template, then parent it to another entity. If the template doesn’t have zeroed transforms, it will always be offset from the parent. To fix this, we need to undo the default transforms before parenting it. It’s a bit troublesome.

Lamp.prototype.initialize = function() {
    let templateAsset = this.app.assets.get(80684337);
    let instance = templateAsset.resource.instantiate();
    // Undo any default transforms
    instance.setLocalPosition(new pc.Vec3(0, 0, 0));
    instance.setLocalEulerAngles(new pc.Vec3(0, 0, 0));

In Unity you can edit prefab transforms by clicking on the prefab in the assets panel, then editing it in the inspector. Unity also has a prefab editing mode which allows users to make changes deeper in the prefab’s hierarchy. Unreal solves this by not even exposing position/rotation when creating an actor blueprint.

We’d appreciate another look into this issue. Thanks!

I’ve linked the above post to the current issue/feature request for this: Template's position doesn't change after clicking "Apply" · Issue #728 · playcanvas/editor · GitHub

1 Like