roslynator
roslynator copied to clipboard
Support for Unity3D MonoBehaviour derived classes
Product and Version Used: Roslynator 2.1.0 (with Microsoft Visual Studio Community 2017 (15.9.11) )
Steps to Reproduce: In a Unity3D Project I create/open a file containing a class that inherits from MonoBehaviour class and is attached to a GameObject, then i edit it in Visual Studio Community 2017.
(Some additional information: Unity3D is a game engine that allows to script/code the behaviours of 'GameObjects' in the engine. One GameObject can have multiple scripts attached. These scripts have to derive from the 'base class' MonoBehaviour. )
Actual Behavior: Methods originating from Unity3D MonoBehaviour class are marked for removal (RCS12) by Roslynator. Possible Explanation for this behaviour: These methods are usually not actively called in code. But the Unity3D will call the methods if they exist in the scripts. Therefore to Roslynator it looks as if the code was not used.
On the page https://docs.unity3d.com/ScriptReference/MonoBehaviour.html I think most of the (possible) methods are listed under "Messages":
Awake
FixedUpdate
LateUpdate
OnAnimatorIK
OnAnimatorMove
OnApplicationFocus
OnApplicationPause
OnApplicationQuit
OnAudioFilterRead
OnBecameInvisible
OnBecameVisible
OnCollisionEnter
OnCollisionEnter2D
OnCollisionExit
OnCollisionExit2D
OnCollisionStay
OnCollisionStay2D
OnConnectedToServer
OnControllerColliderHit
OnDestroy
OnDisable
OnDisconnectedFromServer
OnDrawGizmos
OnDrawGizmosSelected
OnEnable
OnFailedToConnect
OnFailedToConnectToMasterServer
OnGUI
OnJointBreak
OnJointBreak2D
OnMasterServerEvent
OnMouseDown
OnMouseDrag
OnMouseEnter
OnMouseExit
OnMouseOver
OnMouseUp
OnMouseUpAsButton
OnNetworkInstantiate
OnParticleCollision
OnParticleSystemStopped
OnParticleTrigger
OnPlayerConnected
OnPlayerDisconnected
OnPostRender
OnPreCull
OnPreRender
OnRenderImage
OnRenderObject
OnSerializeNetworkView
OnServerInitialized
OnTransformChildrenChanged
OnTransformParentChanged
OnTriggerEnter
OnTriggerEnter2D
OnTriggerExit
OnTriggerExit2D
OnTriggerStay
OnTriggerStay2D
OnValidate
OnWillRenderObject
Reset
Start
Update
Practical example:
using UnityEngine;
public class TestBehaviour : MonoBehaviour
{
void Awake()
{
// check for child objects, etc.
}
void Start()
{
// modify objects gathered in Awake method...
}
void FixedUpdate()
{
// this will run ~60 times/second.
}
}
Expected Behavior: Methods derived from MonoBehaviour methods could be ignored?
If you need more information I'll try to provide it. Thank you.