Editing Scriptable Object

Hi,

I’m following lecture 135 of the RPG Core course, where we are editing the scriptable object. I saw this has been asked a few times, but I did not manage to find any solution.

This is how my scriptable Object looks when I drag it to Visual Studio.

If I got it right this may be because sometimes I have closed the editor without saving.

I did try to delete the scriptable object and create a new one but it did not change the outcome.

How could I fix it?

Many thanks.

What are you trying to fix? This is what a scriptable object looks like

Edit
Can you show your Progression.cs.

Please paste the code, not a screenshot. You can find how to do it here: How to apply code formatting within your post

Thank you for the answer.

this is the Progression.cs code:

[CreateAssetMenu(fileName = "Progression", menuName = "Stats/Progression", order = 0)]

    public class Progression : ScriptableObject

    {

        [SerializeField] ProgressionCharacterClass[] characterClasses;

        public float GetHealth(CharacterClass characterClass, int level)

        {

            foreach (ProgressionCharacterClass progressionclass in characterClasses)

            {

                if (progressionclass.characterClass == characterClass)

                {

                    return progressionclass.health[level - 1];

                }

            }

            return 0;

        }

        [System.Serializable]

        class ProgressionCharacterClass

        {

            public CharacterClass characterClass;

            public int[] health;

        }

    }

What I’m trying to fix is that when I drag the scriptable object from the assets folder into visual studio, it gives me the result that I posted rather than the one Sam has in his video, where you can clearly see all the values and modify the asset file in visual studio. This is how it should have looked like when I dragged it into visual studio:

%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 0}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: c99bf0e04b0f91345a423dd97462b910, type: 3}
  m_Name: Progression
  m_EditorClassIdentifier: 
  characterClasses:
  - characterClass: 0
    health:
    - 50
    - 100
    - 200
    - 400
    - 700
  - characterClass: 1
    health:
    - 40
  - characterClass: 3
    health:
    - 30

So what I read online is that mine looks different for some some saving issues that Unity has with the scriptable objects and some solutions talk about creating a custom inspector, but with my current level I have no idea what it is about. Thank you in advance for the help.

ok, so this is not a big deal, and it has to do with how Unity is storing the values in the asset, probably to save space or something

You health is an array of int, while Sam’s is an array of float. From what I can see, if it’s float values, they will store like Sam’s, but the int values seem to be packed into a byte string;

Your asset is showing
3200000064000000c800000090010000f4010000
split those into parts of 8 (8 bits per byte) and you get

  • 32000000
  • 64000000
  • c8000000
  • 90010000
  • f4010000
    These are 5x 8bit values - in hexadecimal format. We can read them backwards (byte-magic and stuff) so we’ll get
  • 00 00 00 32
  • 00 00 00 64
  • 00 00 00 c8
  • 00 00 01 90
  • 00 00 01 f4
    If we convert them to decimal, we’ll get
  • 00 00 00 32 = 50
  • 00 00 00 64 = 100
  • 00 00 00 c8 = 200
  • 00 00 01 90 = 400
  • 00 00 01 f4 = 500

So as you can see, Unity is packing these int values, but if you were to change your type to float[] (like Sam’s) you will get the normal list like in the lecture

2 Likes

Thank you very much, I would never thought using an int rather than a float would have changed the way how unity saves it. And thank you also for the detailed explanation, it helped me to understand the reasons a bit more.

To be honest, I don’t really know why they did that. Perhaps it’s to save space, but I don’t know. I just took your code and put 1,2,3,4,5 in my health values and noticed the correlation. I have some experience with bytes and stuff, so it wasn’t too difficult to see the pattern

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms