Home > Software engineering >  Saving the Jason file in Unity does not work
Saving the Jason file in Unity does not work

Time:12-14

I was making a simple 3d game, but an error occurred while saving json. It's such a short code that I don't think there's a problem with the code itself.

Here's the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerStatus
{
    public int level;
    public int hp;
    public int attack;
    public int defence;
    public int speed;
}
private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("WarpPoint"))
        {
            Managers.Save.SaveJson<PlayerStatus>(status);
        }
    }

There is no problem in the process of receiving the trigger, but the saving json file does not work properly. How can I solve this problem?

CodePudding user response:

The way is easy. [System.Serializable] on top of your PlayerStatus script that you didn't forget to paste.Attach Serializable! Then it'll probably be saved. I had a hard time with the same error before, but if I don't use it, there will be an error. I hope you have a good day.

  • Related