JetBrains / JetBrains/resharper-unity

Add inspection warning: Unity event function cannot be used both in base type and derived type without virtual

Open
#1,908 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.2k
Forks
142
PR merge metrics
No merged PRs in 30d

Description

Case in point:

```
class BaseType : MonoBehaviour
{
protected bool myExtremelyImportantValue = false;
private void Awake() { myExtremelyImportantValue = true; } // Never runs
}

class DerivedType : BaseType
{
private void Awake() { /* ... */ } // Runs
private void Start()
{
Assert.IsTrue(myExtremelyImportantValue); // Fails, catastrophic failure of the programmer's sanity!!!
}
}
```

An inspection would prevent this easy mistake, and could offer a quick-fix to make `Awake` protected virtual and invoke `base.Awake()` in descendants.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.