C
C#12mo ago

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'.
No description
14 Replies
✟
OP12mo ago
if you need more screen tell me
✟
OP12mo ago
No description
No description
Angius
Angius12mo ago
What exactly is the error?
✟
OP12mo ago
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'.
Angius
Angius12mo ago
Well, there you have it. The Menu class does not seem to have UnityEngine.Component anywhere in its inheritance chain
✟
OP12mo ago
it have it "unityEngine'"
No description
Angius
Angius12mo ago
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?
✟
OP12mo ago
nope bit if i use MonoBehavior my code is full of error
Angius
Angius12mo ago
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 it
✟
OP12mo ago
so i have to put the using UnityEngine (UnityEngine.Component) ?
Angius
Angius12mo ago
No Menu needs to inherit Component Either directly or indirectly Do you know what inheritance is?
✟
OP12mo ago
nope
✟
OP12mo ago
MonoBehaviour is a subclass of Component

Did you find this page helpful?