Hi guys,
Is it possible to serialize UnityEngine.SceneManagement.Scene type of variables?
I have noticed that I cannot convert them to to UnityEngine.Object, which makes me skeptical whether or not it can be serialized.
Any ideas?
Thanks! ![]()
Hi guys,
Is it possible to serialize UnityEngine.SceneManagement.Scene type of variables?
I have noticed that I cannot convert them to to UnityEngine.Object, which makes me skeptical whether or not it can be serialized.
Any ideas?
Thanks! ![]()
Do a two second test in the editor and report back.
If they can’t be directly serialised, you should be able to tokenise them and serialise that.
Also want to convert them to UnityEngine.Object. Not sure what to google to find info on how to tokenize. unity3d Serialization tokenize - Google Search didn’t look useful.
If you’re trying to serialize a scene and hope to save progress that way, forget it. It’s much easier to serialize the name of the scene as a string and then load it later. Serialization and saving in general is a pretty difficult topic I’ve just started scratching the surface of; you really want to make it as easy as possible.
Found an editor only solution:
private void setByName(string sceneName)
{
#if UNITY_EDITOR
var scenePath = UnityEditor.EditorBuildSettings.scenes
.Select(s => s.path)
.FirstOrDefault(s => s.EndsWith(sceneName + ".unity"));
m_SceneAsset = AssetDatabase.LoadAssetAtPath<SceneAsset>(scenePath);
#endif
m_SceneName = sceneName;
}
There is a lot to be said for editor only approaches for strings in the inspector. Its relatively easy to build dropdown lists with all of the valid strings. Underneath its still a string, but it means you aren’t prone to human error like you would be if you manually typed in the string.