question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to reset global values when load scene?

See original GitHub issue

Hi, I created a button to restart my game, but globals are not been reset.

My code is like this:

GameController

    private void SetGlobalVars(Contexts contexts)
    {
        contexts.game.SetGlobals(globals);
    }

My function to load scene:

    public void Restart()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

When the scene has been load, it’s printing error in console about some global value is already setted.

How can I reset my Entitas contexts when the scene is load?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
ghostcommented, Apr 27, 2018

You can see in the exception which group is getting retained Collector(Group(AllOf(Asset, View))), Collector(Group(AllOf(Player, PlayerStatus))). Do you save somewhere in a MonoBehaviour a reference to a Entity? As I said you can clear the collectors of reactive systems also with systems.ClearReactiveSystems().

0reactions
lai32290commented, Apr 28, 2018

Thanks @StormRene ! cleaning reactive systems just fixed my problems!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reset global values when load scene? · Issue #690
Hi, I created a button to restart my game, but globals are not been reset. My code is like this: GameController private void ......
Read more >
How to reset all variables and objects when reloading a ...
You could use OnSceneLoaded to manually reset your static variables (since they are the only ones that persist without an instance of an...
Read more >
Accessing all global variables and resetting them on scene ...
I currently have a few global variables that I use throughout my game. I've found that even if I do a complete re-load...
Read more >
Why my Global Variables are reset on another scene
When I change scenes, ALL of my global variables and object variables are reset to their defaults. I have no idea what is...
Read more >
Resetting static variables when loading scene with ...
You can't “reload” a static variable. It persists for the lifetime of the app and exists on the heap. Your options are to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found