[Solved] Sudden error with no changes made

Hello, i have an error on a script that i haven’t changed the line is this one

this.cam.camera.worldToScreen(this.entity.getPosition(), screenPos);

where this.cam = app.root.findByName(‘Camera’);
since 2 hrs ago it worked… don’t understand what happened.
Edit: the error say
[htmlFollow.js:40]: TypeError: this.cam.camera is undefined
Edit2: seems it doesn’t recognize the camera component in the camera entity

Have you debugged it to see if the data in those variables are correct and this.cam is not null?

yes, this.cam is not null, this.cam.camera is undefined

Have you insert another node into the hierarchy called “Camera”? e.g. do have you changed a model and one if it’s nodes is called Camera?

Try changing findByName to use a script attribute and see if you get the same problem.

Uhm u are right @dave, i have pointed and script.camera and it don’t find it, but i have re-checked all the entites and there isn’t another camera there is xcamera, cameraD, chkcamera (that always existed), bit it seems it point to another node…but more strange…i have added the tag Camera to the camera entity and changed findByName with findByTag and still the same result

I had a proper look through the project and this one is a bit weird and was hard to find.

It appears your Survival+bonfire.json has something in it called ‘Camera’ (Maybe in the model?) and findByName is finding that first (as Dave mentioned above).

This is what I found in the json:

{  
   "model":{  
      "version":2,
      "nodes":[  
         {  
            "name":"RootNode",
            "position":[  
               0,
               0,
               0
            ],
            "rotation":[  
               0,
               0,
               0
            ],
            "scale":[  
               1,
               1,
               1
            ]
         },
         {  
            "name":"Plane",
            "position":[  
               5.63366,
               -7.18166,
               -1.64001
            ],
            "rotation":[  
               -90,
               -150,
               -0
            ],
            "scale":[  
               2.46063,
               2.46063,
               2.46063
            ]
         },
         {  
            "name":"Camera",
            "position":[  
               0.334575,
               10.9328,
               10.6303
            ],
            "rotation":[  
               -91.943,
               44.2327,
               -92.4998
            ],
            "scale":[  
               1,
               1,
               1
            ]
         }

To fix it, you can either:

  • findByTag and tags would work but you have to remember that returns an array even if there is only one entity found.
  • Rename the camera to something more unique
  • Remove or rename the mesh/object in the model called Camera
  • Use a script attribute with an entity reference to the Camera

Didn’t thought that the models can have also a camera attribute :blush: and didn’t thought that that is found as node…i see…every day i’m learning something new…also after 1 and half year…i will import the fbx in 3ds and export it again, in my export options cameras are not included, this model was from web and didn’t checked it coz was very simple. Thanks a lot @steven and @dave