- Home /
Would abuse of inheriting from extended MonoBehaviour hurt the performance?
public class ExtendedMonoBehavior : MonoBehaviour
{
private static bool _isServer;
public static bool isServer
{
get
{
if (_isServer == default(bool))
{
if (UnityEngine.Object.FindObjectOfType(typeof(Server)) != default(UnityEngine.Object))
{
_isServer = true;
}
else
{
_isServer = false;
}
}
return _isServer;
}
}
private static EventDispatcher _eventDispatcherComponent;
public static EventDispatcher eventDispatcherComponent
{
get
{
if (_eventDispatcherComponent == default(EventDispatcher))
{
_eventDispatcherComponent = (EventDispatcher)UnityEngine.Object.FindObjectOfType(typeof(EventDispatcher));
if (_eventDispatcherComponent == default(EventDispatcher))
{
throw new System.Exception("Can't find EventDispatcher in your scene");
}
}
return _eventDispatcherComponent;
}
}
public static T[] ConvertToArray<T>(IList list)
{
T[] ret = new T[list.Count];
list.CopyTo(ret, 0);
return ret;
}
public static Dictionary<GameObject, GameObjectParameters> networkedGameObjectsWithParameters = new Dictionary<GameObject, GameObjectParameters>();
public static Dictionary<NetworkPlayer, NetworkPlayerParameters> networkPlayersWithParameters = new Dictionary<NetworkPlayer, NetworkPlayerParameters>();
public static IControllable controlledComponent=default(IControllable); // client only
}
so on and so forth... of course i have all my scripts inheriting from it. I could put them into other script using extension methods instead. would that make me cry in the long run?
I honestly hope not, because ive done something similar but with Character$$anonymous$$otor.
Realistically speaking though, its just an inherited class. The only performance problems would be caused with bad coding practices.
Answer by MarkFinn · Dec 26, 2012 at 06:49 AM
There's no technical reason that this shouldn't be ok. It will make your code more complex over time, but that's down to being strict with your code standards.
Your answer
![](https://koobas.hobune.stream/wayback/20220613085854im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Having runtime functionality and editor extension in one script 1 Answer
MonoBehaviour Update() performance vs handling updates in a single UpdateManager script 0 Answers
Component extension methods not showing 1 Answer
MonoBehavior, ScriptableObject and Object memory usage & performance 0 Answers
Efficient way to scan surrounding with large number of objects 0 Answers