Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Serialization Problem

Discussion in 'External Tools' started by Zhang_Dev, Mar 30, 2020.

?

Serialization Problem

  1. I don't Know

  2. I do Know

Multiple votes are allowed.
Results are only viewable after voting.
  1. Zhang_Dev

    Zhang_Dev

    Joined:
    Feb 19, 2020
    Posts:
    2
    I'm trying to save scriptable objects in my game.Help!
    PlayerSettings.cs
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Runtime.Serialization;
    4. using UnityEngine;
    5. [CreateAssetMenu(menuName = "PlayerSettings")]
    6.  
    7. public class PlayerSettings : ScriptableObject
    8. {
    9.     public List<Tool> tools;
    10.     public List<Sword> swords;
    11.     public Tool selectedTool;
    12.     public Sword selectedSword;
    13.     public float cash;
    14.     public float multiplier;
    15.     public float workers;
    16. }
    17.  
    Tool.cs
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. [CreateAssetMenu(menuName = "Tool")]
    5. public class Tool : ScriptableObject
    6. {
    7.     public float strength;
    8.     public float cost;
    9. }
    10.  
    Sword.cs
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. [CreateAssetMenu(menuName = "Sword")]
    5. public class Sword : ScriptableObject
    6. {
    7.     public float damage;
    8.     public float cost;
    9. }
    10.  
     
  2. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    534
    Lists aren't serializable; try using arrays instead :)
     
  3. Zhang_Dev

    Zhang_Dev

    Joined:
    Feb 19, 2020
    Posts:
    2
    Thanks!
     
unityunity