What does Uncaught TypeError mean?

Hi all
I have just started using PlayCanvas and am having some coding difficulties.

If I try to call a function (such as this.entity.model.hide()), when I try to launch the game an error message saying “Uncaught TypeError” comes up. How do I fix this?

Also, how do I code a game to change scenes?


I don’t think you can use this.

Maybe try:

this.entity.model.enabled = false;

The error usually means that the function you called does not exist. Try what @albertos mentioned above, it’d definitely work.

Take a look at https://developer.playcanvas.com/en/tutorials/ to get started with the basics. Check out https://www.codecademy.com/learn/introduction-to-javascript to get a grasp on coding and JS fundamentals. Happy developing @Charlotte_Clements!

https://developer.playcanvas.com/en/tutorials/changing-scenes is the tutorial sample project for this

Thanks, disabling the entity works.
I looked at the tutorial project for changing scenes and tried to write my own code but it isn’t working for me… here’s my code:

var ChangingScenes = pc.createScript('changingScenes');
ChangingScenes.attributes.add("sceneName", {type: "string", default: "", title: "Scene Name to Load"});
ChangingScenes.prototype.initialize = function(dt) {

// update code called every frame
ChangingScenes.prototype.update = function(dt) {

ChangingScenes.prototype.loadScene = function (sceneName) {
    // Get a reference to the scene's root object
     var oldHierarchy = this.app.root.findByName ('Root');
     console.log('function working');
    // Get the path to the scene
     var scene = this.app.scenes.findByName ('Untitled2');
    // Load the scenes entity hierarchy
     this.app.scenes.loadSceneHierarchy(scene.url, function (err, parent) {
        if (!err) {
        } else {


// swap method called for script hot-reloading
// inherit your script state here
// ChangingScenes.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/

Generally all the game logic code should be in the functions of the script types rather than global space.

e.g in the Update function, as part of a callback on an event, etc.

I’m assuming you want to change scenes based on some action such as a collision or button press?

I want to be able to change scenes when a key is pressed. What’s the simplest way to do that, and could someone post an example?
Thanks :slight_smile:

Hey @Charlotte_Clements,

Check out this post - [SOLVED] How to change scenes using interface buttons