[SOLVED] Weird bug in my game

ok this is the code:

var ChangeCutScene = pc.createScript('changeCutScene');

ChangeCutScene.attributes.add("cutscene", {
    type: 'entity'

ChangeCutScene.attributes.add('extraDisable', {
    type: 'entity'

ChangeCutScene.attributes.add('changeTimeout', {
    type: 'number'

// initialize code called once per entity
ChangeCutScene.prototype.initialize = function() {
    this.entity.element.on('mousedown', this.onPress, this);
    if(this.changeTimeout > 0)
                this.cutscene.enabled = true;
                try{this.extraDisable.enabled = false;}catch(e){}
                this.entity.enabled = false;
        }, this.changeTimeout);

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

ChangeCutScene.prototype.onPress = function(event) {
                this.cutscene.enabled = true;
                try{this.extraDisable.enabled = false;}catch(e){}
                this.entity.enabled = false;

this code is basically frame changer in a cutscene, designed to go either on button click or on auto timeout, thing is, auto-timeout works fine and so should the click (onPress) but for some reason the onPress doesn’t work. The code works when I haven’t switched scenes, meaning basically I change scene at one point and when I enter the scene which has time code, the code inside onPress just doesn’t work while the timeout function works perfectly, what is this weird bug?

Are you sure the onPress function is being called? Is use input enabled on the element that the script is on? Can you provide a link to a project that shows this issue.

100%, I have logs and everything, its triggering every statement in there without any error but somehow some statements are just not triggered , like the one in try catch block doesn’t get triggered inside the onPress but that same statement gets triggered inside the setTimeout? like whaat?

If you can provide an example project of the issue, that would help. I can’t see anything wrong from the code posted here.


this is the project but I am going to redo the game a different way as many things are getting weirdly bugged out because of this one thing but please take a look and see what can be the problem, my code may look messy but they follow a general theme of re-useability. the problem begins when I switch from scene “game” to scene “over” they are both working fine on their own but when paired together they are bugging out, which you can see by losing the main game, to lose just stand in the lane of obstacles and get hit by cars, potholes, workzones and the game will take you to scene 3 which is “over” and there will be “continue” button that bugs out, that same button works perfectly when I load that scene( “over” scene ) first and own its own, instead of going through “game” scene. the game controls are “A” and “D” to move left and right, respectively

Hi @sir_akc! It is maybe caused by a number of errors in your game. I recommend that you fix the errors first.

I am also curious what to do if all three lanes are blocked …

the game is the mess, I will redo everything from start

The errors only arise when clicking on a button. So I think they are fairly easy to fix. But it can indeed help to start over. I did that too with my own game, but I notice that as you progress in the remake, everything starts to get messy again.

what is hitPadding? the console is logging is output when I am switching between scenes and I dont know what this error is about


If you think this is the same problem, did you also try the solution of @yaustar to deleting the old hierarchy first before loading the new one?

I found the solution, there is an update function accidently calling the loadScene too many times therefore the error, so I just added a bool to only trigger it once, case closed

1 Like