[SOLVED] Entity disappears with reparent

I have some problems with setting the weapon-output in front of the weapon. First i try to do it with reparent the weapon-output to the weapon (and after that i want to set an offset to the front of the weapon). But if i use this.weaponOutput.reparent(this.weapon) the weapon-output disappears.

Can someone tell me why this happens? I create a sample project so you can see the problem.


Hi @Albertos,

Reparent.prototype.initialize = function() {
    weapon = this.entity.findByName("Rifle");
    weaponOutput = this.entity.findByName("WeaponOutput");

A few things:

  • this.weapon is not defined anywhere, maybe you mean weapon?
  • Rifle seems to be a GraphNode in the Soldier model, adding entities as children can work, that’s correct. But you need to adjust scaling, for example:
Reparent.prototype.initialize = function() {
    weapon = this.entity.findByName("Rifle");
    weaponOutput = this.entity.findByName("WeaponOutput");

Hay @Leonidas,

I indeed forget the this in the sample project. Sorry for that.
How i can set the scale the same as the orginal, i think if i use a wrong scale i also get a wrong ofsett?

I have update the sample project with the offset code and in the sample project it works fine, but if i use the same in my game, i get for every enemy a diffrent wrong offset. I dont understand why because i clone the same entity so i expect the same result on every cloned enemy…

Scaling is always local and is affected by the parent/hierarchy scale.

You can easily fix the scale to stay same, taking into account the original scale of the bone node. Here is an older post with a resolution for this issue:

I update the sample project again. I added a couple more soldiers with different rotations. Now you can see what also happened in my game. Also the scaling is still incorrect.

Hey @Albertos,

You did everything fine, you just need to apply the original scale of the cone object (0.3,0.3,0.3) in place. Like this:

Reparent.prototype.initialize = function() {
    this.weapon = this.entity.findByName("Rifle");
    this.weaponOutput = this.entity.findByName("WeaponOutput");
    this.weaponOutputScale = this.weaponOutput.getLocalScale();
    this.scale = this.weapon.getWorldTransform().getScale();
    this.weaponOutput.setLocalScale(this.weaponOutputScale.x * 1/this.scale.x, this.weaponOutputScale.y * 1/this.scale.y, this.weaponOutputScale.z * 1/this.scale.z);
    // this.weaponOutput.setEulerAngles(this.weapon.getEulerAngles().x, this.weapon.getEulerAngles().y, this.weapon.getEulerAngles().z+90); 
    // this.weaponOutput.setPosition(this.weapon.getPosition().x-1, this.weapon.getPosition().y-0.55, this.weapon.getPosition().z); 

All enemies are finally shooting in the right direction. I couldn’t have done this without your help. Thanks @Leonidas!

1 Like