Rigidbody is undefined

Hey guys i have a problem that keep occuring pretty often, when the level is changed though ingame event my rigidbody for player suddenly dissapear from the components as i debugged, although it should be there , it is there when i play the certain scene from the editor but dissapear when scene is changed, there is no script that is removing rigidbodies or so on. this is what debbuger showed up:

Are you remembering to unsubscribe from global events when the entities are destroyed? Looking at the screenshot, it doesn’t look like the script unsubscribes from the event when it is destroyed.

Hey, thanks for response @yaustar, can you tell me how it is done ? :slight_smile:

See this thread: Change scene doesnt work properly

Hi @smokys

I can assist you with your requirement.

PM sent please check.

Please reply to move forward.

Best
Noah

I guess you are talking about this code, right?

this.entity.component.off('event', this.Function, this);

And we want to unsubscribe to global event. so how should it looks like?
I understand how to make it work when the component is collision, im missing basic understading of unsubscibing event obviously

Hey, feel free to help :stuck_out_tongue:

It will look like this:

var onRespawn = function() {
    context.entity.rigidbody.teleport(checkpoint);
};

this.app.on('player_respawn', onRespawn, this);

this.on('destroy', function() {
    this.app.off('player_respawn', onRespawn, this);
}, this);
1 Like