Error: camera.script is undefined

I’m working with a fork of the TPS Demo. I changed the original player model to mine, added my animations, and changed the names of the animation files in the playerAnimationHandler.js script. That is ALL I did to the scene. It all works fine, except now I’m getting this error “camera.script is undefined” when I run the project. This breaks the project as the player movement doesn’t work (any movement you currently see is built into the animations, which I’ll have to figure out how to get rid of later). I believe this is coming from the playerMovement.js script, right in the initialize function:

PlayerMovement.prototype.initialize = function () {
    var app = this.app;
    var camera = app.root.findByName('Camera');
    this.cameraScript = camera.script.cameraMovement; //this is where the error is coming from as far as I can tell
};

It might just be that my brain isn’t working properly, but I can’t seem to find any reason why this error should be happening as the ONLY change I made to the code was changing the names of the animation files. As stated before, the player entity is the same too, besides the different model and animation files.

Here’s the link to my project (Look in the Main2 scene, and ignore the Network.js and socket.js scripts. Those aren’t currently implemented.): https://playcanvas.com/editor/scene/975168

Thanks in advanced!

Hi @GeekyDud,

It seems the issue is your imported model contains a node named ‘Camera’ (most likely exported by your 3D modelling app). So the findByName method will find that Camera named node first, before reaching your camera entity.

Replace the default code with a more specific query method and it will work fine:

PlayerMovement.prototype.initialize = function () {
    var app = this.app;
    var camera = this.entity.findByPath('Camera Axis/Camera');
    this.cameraScript = camera.script.cameraMovement;
}; 
2 Likes

I wasn’t sure what that was referring to in the console… stupid Blender… :rofl: Thanks! I’ll probably end up going back into Blender and trying to remove that to avoid confusion.

1 Like

In Blender you can also export only your selected nodes, there is an option on the export FBX dialog.

I use it quite often to avoid including unnecessary cameras or lights in the file.

1 Like

Never saw that before… I’ll definitely start using it whenever I export my models now. Thanks for the words of wisdom!