#OnLevelFinishedLoading

1 messages · Page 1 of 1 (latest)

obtuse scroll
#

heya. I have a scene director object, with the DontDestroyOnLoad() property. it calls OnLevelFinishedLoading() when a scene is loaded, but only the first time that level is loaded. If the level is loaded again, such as going to the main menu and then returning, it is not called again.

OnLevelFinishedLoading() is called with SceneManager.sceneLoaded += OnLevelFinishedLoading, and I feel like that's the issue, but I'm not sure with what to replace this code with.

marsh spire
#

Please attach your code because explaining your code in paragraph would just confuse people

obtuse scroll
#

sounds good

marsh spire
#

!code

merry cypressBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

marsh spire
#

Put debug log inside the OnLevelFinishedLoading() to make sure it is being called

#

Debug.Log(scene.name)

obtuse scroll
#

just gonna test the code block thing first

marsh spire
#

use the ` under ESC

obtuse scroll
#
void OnEnable()
    {
        DontDestroyOnLoad(gameObject);
        SceneManager.sceneLoaded += OnLevelFinishedLoading;
    }



void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
    {
        if (scene.name != "MainMenu")
        {
            currentLevel += 1;
        }
#

ah

#

neat

marsh spire
#
void OnEnable()
    {
        DontDestroyOnLoad(gameObject);
        SceneManager.sceneLoaded += OnLevelFinishedLoading;
    }
void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
    {
Debug.Log(scene.name);
        if (scene.name != "MainMenu")
        {
            currentLevel += 1;
        }```
#

see if the debug log is called (it should)

obtuse scroll
#

it calls when the level is loaded

#

so now im not sure where the problem is

marsh spire
#

what it say?

obtuse scroll
#

L_00_HUB when in first level, and MainMenu when in menu

#

which is what it should be doing

marsh spire
#

then it works fine

obtuse scroll
#

it might be the stuff inside then

marsh spire
#

do you expect it to do other thing?

obtuse scroll
#

yeah, but at first i thought it was the load

#

it instantiates the player

#

that works the first time, but the second time it loads the character, you can't control it

marsh spire
#

No clue what you mean now blushie

#

ah

obtuse scroll
#

im looking through my spaghetti code to find why its doing that now

marsh spire
#

then you left the character controller in the old scene

obtuse scroll
#

im not sure what that means

marsh spire
#

whatever moves your character

obtuse scroll
#

i have a moving script on the player character that's on a prefab, but looking in the inspector on the reload and it looks the same

#

im looking through now to see if i missed anything

#

so looking at it

#

it looks like the physics don't work on reload?

#

because i tried an enemy spawner script i made another time, it spawns the enemies but they don't move either

#

im getting more confused

marsh spire
#

Idk as well, I dont have any idea about your game

obtuse scroll
#

not sure if i need to send a video or something

#

on first load i can move fine and enemies spawn

#

but going back to main menu

#

its just this and nothing moves

#

would time scale do something like this?

#

oh holy shit

#

the time scale is 0 the second time around

#

where did i do that

#

well

#

it works now

#

turns out i had a piece of code that turns time scale to 0 in main menu

marsh spire
#

gratz you just solved your problem UnityChanOkay

obtuse scroll
#

lmao

#

thanks for being there lol