Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

Questions about changes to UnityEngine.Random. Random.Seed deprecated

$
0
0
Previously, I've been using PlayerPrefs to store an integer from Random.seed to save the level and restore the integer from PlayerPrefs to Random.seed to restore the level. The code to save the seed. PlayerPrefs.SetInt("Seed", Random.seed); PlayerPrefs.Save(); The code to restore the seed. if (PlayerPrefs.HasKey("Seed")) { Random.seed = PlayerPrefs.GetInt("Seed"); } Recently, however, Random.seed has been deprecated and replaced with Static Variable Random.state and Static Function Random.InitState. Now I changed my restore code to look like this if (PlayerPrefs.HasKey("Seed")) { //Random.seed = PlayerPrefs.GetInt("Seed"); Random.InitState(PlayerPrefs.GetInt("Seed")); } and that seems like a simple enough change and seems to work the same as before. However Random.state does not return an Int. I think maybe it returns it's own data type of Random.State? If that's correct, then I don't know what to do with that to store it. I don't know how to display it either. I find it useful to use Debug.log to display the value from Random.seed so I know if the sequence is changing when it's not supposed to be. I've read https://docs.unity3d.com/ScriptReference/Random-state.html and I see that I can store a Random.state to a variable of type Random.State, but that doesn't help me display it for debug purposes, and I'll basically have to write my own class to store and recall data from the disk just to be able to handle it. Does anyone know why Unity made these changes? Does anyone know what the benefit is. Is there some central location where these changes are discussed that I can go to?

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>