Button prefab uses same OnClick event between different scenes

Hi all,

I’m experiencing a bit of a weird problem when creating button prefabs for my 2D game. I’ve got one, simple button prefab which contains a sprite for it’s background image and a text. The prefab doesn’t have anything on it’s On Click event.

The button prefab is mainly used for running some serverside logic and then load another scene when it’s done. So let’s say, I have a “Login scene” and a “Create avatar scene”:

On the login scene, I have my button prefab, which is the login button. It logs in the user and the calls SceneManager.LoadScene(“Create avatar scene”);

On the “Create avatar scene”, I have a “Continue” button prefab. The “Continue” button prefab saves the selected avatar and then starts the game.

However, since I’m using a prefab (it works if I create separate, new buttons), it seems that the “Continue” button prefab performs the “Login” button prefabs logic. Or in other words: the OnClick event “persists” from the previous scene to the next scene. So all it does is calling the login method again, even if the button is on a completely difference scene.

Does anyone know why this happens? As I wrote, it works just fine when I create a new button from scratch rather than using my button prefab.

Thanks in advance.

I can’t help you much with this but are you sure the LoadScene is not attached to the prefab.

Maybe the prefab is built to load only one particular scene and it cannot transition.

cheers