Best Ways to organize variables?

Hi all,

I like to make my scripts organized and easy to read, but I’ve got too many variables lying around and the inspector has become clustered and disorganized; so I’m trying to find a way to tidy up my variables but no on line documentation has been able to help me.

I’m looking for a way to categorize my variables and put them under a collapsible menu. So I created different classes for different types of variables, like this:

[System.Serializable]
    public class ShootVariables : System.Object {
        //My variables go here
    }
    public ShootVariables shootVariables = new ShootVariables();

But every time I need to reference to variables inside that class, I have to first make reference to that class, which is not very efficient:

shootVariables.damage = 5f;
recoilVariables.kickAmount = .5f

Is there a way to just use the variables without referencing the class?
I feel like I might be doing something wrong; Or could there be a different ways to create the collapsible menu? Or just a different way to organize your variables?

Thanks

Your scripts shouldn’t have that many variables. If you’re getting large amounts of them, then you might be having a single script do way too much.

If you’re talking about game settings, in that case I usually implement them in a ScriptableObject, and make that object a Singleton that loads the ScriptableObject and serves out the values in a global manner.

Hi There

No one seems to be able to answer your question. No one can know your intent specifically. The scope of the question should be reduced.

Cheers!

This question is years old, but I too ended up here before I found the actual answer which I’ve linked below in hopes it can help someone else. The header attribute will make your inspector a lot tidier long before you reach “split into smaller scripts” levels of variables. cheers!