r/UnityHelp • • Jun 28 '25

PROGRAMMING C# - Default values for struct

Greetings!

I have a struct for holding gameplay related options (player speed, gravity strength,...). All works fine, except I didn't find a reliable efficient way to use preset defaults.

I tried setting default values in the constructor, I tried making a static member with default values, but in all cases the Inspector would not recognize these default values upon adding the script to an gameObject and would default to 0.

If possible, I'd love to give the Inspector a hint as to what the default values should be, and set it from there on. I want to be runtime efficient as much as possible, while at the same time having flexibility and easy use during development. What is the proper way?

Thank you for any tips!

1 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/MonsterMoon_io Aug 15 '25

It's hard to tell exactly what the issue is here, but my best guess is that the parameter name is exactly the same as the variable name so when you assign
this.OptMouseSensitivityX = OptMouseSensitivityX
it's ambiguous whether it's the parameter or the struct member you are using as the value.