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);
            instance.setLocalPosition(pos);
            
            // Attach to Entity 
            targetEntity.addChild(instance);

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.