-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to select protection level of Unity Event/Lifecycle functions #2375
Comments
Could you provide some reasons for changing this? These event functions are only supposed to be called by Unity, so there is little reason to make them visible to user code |
That settings code is just a plain block of handwritten text 😄 I wouldn't put too much stock in that one. It looks like there are two different issues here - calling directly and overriding. Calling directly would require generating at either |
The overriding appears to work fine if there's a subclass: if i have:
and I make:
Asking for a unity event override does the right thing and adds a alt-enter is pretty quick to do, so that's a good workaround, just be handy for those that declare them public-by-default to not have to do that step :D |
It's a common policy in many studios to have all Unity messages protected by default. It's also part of the Microsoft/UnityVS analyzers (albeit opt-in): https://github.com/microsoft/Microsoft.Unity.Analyzers/blob/main/doc/UNT0021.md Silently erasing a base message in a derived class without realizing it is a very common source of bug. I've several times found lot of bugs "for free" when landing in a new codebase by mass replacing "void Update" by "protected void Update()"... suddenly the compiler does its job, warning that things look fishy! Then you can fix it (add virtual, or indeed erase with new if that was the intention), but at least you're aware of it, it's not silent anymore.
IMO this is the wrong way to look at it; it's not about making them visible, it's about respecting the OO paradigm. Unity made a horrible mistake years ago with those magic messages, they clearly should have just been virtual methods (somehow it seemed more Flash-like and friendly at the time...). It's too late for them to change MonoBehaviour now, but clearly all their new APIs now use proper OO (either base classes with virtuals, or interfaces). |
Currently when generating event functions, Rider generates them all as private, I was wondering if an option could be added to set the default protection level of generated event functions?
(related to: #1493 )
The text was updated successfully, but these errors were encountered: