[SOLVED] Is it possible to modify the type of variable in the inspector?

Hi all -

I plan on creating a class - Attribute.cs - to store some of my player attributes (health, money, experience, etc). These are currently stored as variables, but managing them is becoming increasingly more complicated as I create more and more of them - so the idea is to create an array or a list of attributes that I could loop through and edit directly from the Inspector.

The problem is that some of these variables are integers, others are floats, and yet others are doubles - so I either have to inherit from the Attribute class to create sub-classes such as DoubleAttribute, FloatAttribute, and IntAttribute, or I need a way to change the type of the variable stored in the class.

Is there a way to set the type of the variable stored in the class in the Inspector? Something like a dropdown that basically says “for this object in the list, the type of variable amount is double, and for that one, it’s float”?

Why do you need to loop though it? Just asking because that seems like a lot of work just to be able to loop through something.

You could use Attribute interface and make a Attribute::class for each attribute.

That’s the only way I see of storing different data types into an array. And iterating through it is STILL going to be a pain since you’ll have to find out which implementation of Attribute interface you’ve stumbled upon within the array.

What is wrong with having a Player.cs class with all required variables neatly stored in it? Why would you do this? WHY?

The reason I’m looking to get rid of relying on variables is because I often have to call a method that affects all of them (for example, when saving/loading the game, when resetting it, etc). In total, I have about five methods that all need to reference all of the variables that I created. This is fine when I only have a handful of variables to work with, but becomes a total mess when I have to work with 20+ - it’s only a matter of time before I add a new variable but forget to also add it to one of the methods calling it, etc.

Besides, if I had a dedicated class, I could also write some helpful stuff directly into that (for example, I could include a “default value” variable within that and then, when the reset is called, have the reset function revert the value to the default value assigned specified).

In your example I’d just make an overwrite of toString() in player class, So I would just save that string.
And just make a constructor that takes a saved string for loading.

Complexity is like energy. You can’t get rid of it. You may only move it.

This sounds like a far simpler solution indeed. Thank you!

AAAAAAH! Wait!

Just remembered C# has this jewel

https://stackoverflow.com/questions/5877808/what-is-serializable-and-when-should-i-use-it

I would recommend looking into it.