It works well - count of each item is saved and carried over to second scene (I see that in the inspector window).
However the UpdateDisplay methods that are supposed to update text on the UI are not working. Meaning that the UI manager does not update the values on Start for some unknown reason. GetComponent finds the UIManager no problem although I’ve had to add this to the UIManager script:
Any idea why these methods do not update the UIManager when they are in Start? If I’d know what is the cause of it I could work on some solution but here I’m completely baffled.
If the UI was not included in the hierarchy marked as DontDestroyOnLoad(), even if a new one was produced when you got to the next scene, it would be a different one.
Some solutions:
the solution you found by putting it in Update (basically late-finding what you need)
reload both the inventory and the UI, but have another GameManager that only keeps the data, and both reach to that for their reference data
use a separate data-abstraction package… and this is where I blow my own horn because I made one of these called Datasacks. It’s a free package and essentially lets you divorce UI updates from code pretty much completely.
Thank you Kurt-Dekker for looking at my issue and offering some advice.
UIManager is not included in the hierarchy marked as DontDestroyOnLoad() true, but even when it is - it does not change the outcome of the executed code.
What is absolutely weird is that code in Start method is executed properly (all the methods are called) but the UIManager doesn’t want to update on start of the scene.
I would like to figure out why these four methods are executed but there is no reaction from the UIManager. I thought that it may be related to the order of objects that are loaded in the scene/code but even using coroutine with 3s delay before these methods are called is not making the UI to update. It drives me nuts as it seems illogical to me
I do not want to keep them in Update as this is very “uneconomical”. Your third proposition is an overkill for what I need.
The second proposed option could work well, but I’ll need to rebuild my inventory as a List as there is no other quick way to share private variables and I wouldn’t want to make them public.