#Problems With Objects On Scene Load.

1 messages · Page 1 of 1 (latest)

dawn heath
#

When load play scene at first time all works. But if i for example return back to main menu and load play scene again some stuff don't work, saying that objects were destroyed but all of them are in the scene and are attached to classes. Some of them don't really have dependencies between each other. For example Audio Manager works with events only, so other scripts just have to call events with no attention to Audio Manager missing parts.
P.s.

  • I check events for null.
  • I tried to somehow "unload" scenes before loading new one, so next time loading it will be like first.
frigid jackal
# dawn heath When load play scene at first time all works. But if i for example return back t...

Well I don't really have the full context, but one thing you could try is moving the events so that they are subscribed to in the OnEnable method and unsubscribed to in the OnDisable

private void OnEnable()
{
  PlayerV2.PlayerScored += PlayScoreSound;
}

private void OnDisable()
{
  PlayerV2.PlayerScored -= PlayScoreSound;
}

I'm doubt this'll fix your problem, but it's good practice to unsubscribe events upon being disabled and subscribe upon enabling.

Also, are the audio sources still properly referenced when reentering the scene?

dawn heath
#

Ye all good with references, but you can be right about events. Im gonna try it. Thank you!

dawn heath