Json파일로 읽고 쓰기 위해 테스트를 해보던 중
클래스를 Json스트링으로 변환하는건 잘 되는데,
Json스트링을 다시 해당 클래스 타입의 객체로 변환해줄려니까 다음과 같은 오류가난다!
ArgumentException: Cannot deserialize JSON to new instances of type 'JsonTestClass.'
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at
해결방법은
https://answers.unity.com/questions/1308015/jsonutility-cannot-deserialize-json-to-new-instanc.html
[JsonUtility] cannot deserialize json to new instances of type X - Unity Answers
answers.unity.com
바로 직렬화하려는 클래스에서 MonoBehaviour 상속을 없애주면 된다!!
이유는?
MonoBehaviour는 해당 클래스를 컴포넌트로 만든다는 것을 의미한다.
Unity에서 컴포넌트는 객체를 생성할 수 없고 GameObject에 붙어서 동작하게 된다.
여기서! Json스트링으로는 만들어지지만, Json스트링을 다시 객체로 만들려고 할 때, MonoBehaviour 때문에 객체가 만들어지지 못한다.
그래서 다음과 같은 오류가 뜬다.
'Programming > Unity' 카테고리의 다른 글
[게임 개발-문제 해결] Unity2D 탑다운(TopDown) 게임에서 그림자 (0) | 2022.02.16 |
---|---|
[Unity] VR테스트 겸 Unity 앱 만들고 빌드했는데 실행이 안됨 (0) | 2022.01.03 |