Hi, I am trying to store the position of an entity that is referenced in an script. The problem is that the following line:
console.log("Pos: " + this.refEntity.getPosition());
Shows “Pos: [NaN, NaN, NaN]” in the initialize and the first update. The crazy thing is that the second updated (and the following ones) shows a correct value.
Here is the complete script:
pc.script.attribute('refEntity', 'entity', null);
pc.script.create('CameraManager', function (app) {
// Creates a new CameraManager instance
var CameraManager = function (entity) {
this.entity = entity;
};
CameraManager.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
console.log("Pos: " + this.refEntity.getPosition());
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
console.log("Pos: " + this.refEntity.getPosition());
}
};
return CameraManager;
});