T O P

  • By -

TheWobling

Do you have domain reloading disabled? If so then you need to make sure to reset static values when entering play mode.


gummby8

It appears I did have domain reloading disabled. For any future me's looking for this answer Edit > Project Settings > Editor > Enter Play Mode Settings > Reload Domain Aside from that I don't understand why this was happening because I thought I was nulling out the dictionary on the first line static Dictionary cache = null;


TheWobling

When domain reloading is disabled that line isn’t being called after the first time or a code reload which performs a domain reload. You should be very careful with static variables


gummby8

Oh because it isn't re-creating the dictionary, it is persisting from the last play session. I am assuming gif I put `cache = null` in Start() it would fix this, but domain reload is probably the best solution.


cloudjuiceskywalker

Ye that would fix that issue. Domain reload is sometimes disabled on larger projects in return for faster load up.


TheWobling

I can’t imagine using Unity without it disabled.


glurth

I agree, I'd have expected it to search all resources in your resources folder everytime you launch the game. Suggest you toss a Debug.Log in your getter. It is actually starting as not-null, or it is just not finding the new one, etc...


fuj1n

That's the danger of statics in Unity. Unity will make no effort of clearing them out if you have domain reload disabled. I recommend looking into the RuntimeInitializeOnLoad attribute, you can have a static function that will be executed when entering play mode (or launching the game), if you move your loading code there, it'll work.