error CS0311 in my loader
Error CS0311 Unable to use type 'HLTool.UI.Menu' as parameter of type 'T' in generic type or method 'GameObject.AddComponent<T>()'. There is no implicit reference conversion from 'HLTool.UI.Menu' to 'UnityEngine.Component'.
14 Replies
if you need more screen tell me
What exactly is the error?
Error CS0311 Unable to use type 'HLTool.UI.Menu' as parameter of type 'T' in generic type or method 'GameObject.AddComponent<T>()'. There is no implicit reference conversion from 'HLTool.UI.Menu' to 'UnityEngine.Component'.
Well, there you have it. The
Menu
class does not seem to have UnityEngine.Component
anywhere in its inheritance chainit have it "unityEngine'"
Uh, that's a namespace you're importing, yes
Does not mean that
Menu
inherits, at some point, from Component
Or does Overlay
inherit Component
?nope
bit if i use MonoBehavior my code is full of error
Why would you use
MonoBehavior
?
Menu
needs inherit from a Component
, as the error says
You can use .AddComponent<T>()
only when T
is a component
So either literally is the Component
class, or inherits from itso i have to put the using UnityEngine (UnityEngine.Component) ?
No
Menu
needs to inherit Component
Either directly or indirectly
Do you know what inheritance is?nope
Inheritance in C# - C#
Learn to use inheritance in C# libraries and applications.
MonoBehaviour is a subclass of Component