I followed Brackeys tutorial on Youtube to Save&Load files but i can not save static variables with this method because they can not be instantiated. I guess i could try to change every static variable to a nonstatic variable but i like to use static variables in general. Everything else works fine. Help would be appreciated!
Keep your runtime classes totally separate from serialization data classes and there will be no issue, for example:
runtime state classes:
public class MySceneController : MonoBehaviour
{
public static int Score = 0;
}
public class Player : MonoBehaviour
{
void Awake () {}
}
serialization data class (what is being saved):
[System.Serializable]
public class GameState
{
public int player_score;
public Vector3 player_position;
}
then:
var gameState = new GameState();
gameState.player_score = MySceneController.Score;
gameState.player_position = player.transform.position;
/* code that serializes and writes gameState to file */