I am wondering what constraint is needed for a class to be able to implicitly reference UnityEngine.Component. The error cs0311 mentions doing something to enable an implicit reference or identity conversion. I’m not sure what a class needs to be able to implicitly reference UnityEngine.Component.
Would help to show us your existing code.
It sounds like you’re trying to use something that is not a Component in a place that requires a Component.
Without seeing your code it’s hard to say much more, but the gist is you’re trying to put a square peg in a round hole.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using UnityEngine.Networking;
namespace ULogger
public sealed class Manager
{
private bool x;
private string id;
private int uid;
private static int counter = 0;
private static Manager inst = null;
public static Manager GetInstance
{
get
{
if(inst == null)
{
inst = new Manager();
}
}
}
private Manager()
{
x = false;
id = "abcde";
uid = 2;
counter++;
}
}
This is what I have so far, I’m trying to make a singleton class, compiling it into a dll and putting it as an asset in unity, but when I do something like this
GameObject x = new GameObject(“yz”);
yz.AddComponent();
I get
"They type ‘Ulogger.Manager’ cannot be used as type parameter ‘T’ in the generic type or method ‘GameObject.AddComponent()’. There is no implicit reference conversion from ‘ULogger.Manager’ to ‘UnityEngine.Component’.
What do I need to add the correct implicit reference conversion?
What is up with people pre-compiling .dlls lately? What’s wrong with just making regular scripts in Unity? Especially when you don’t understand basic Unity principles.
There is no correct conversion because Manager doesn’t inherit from component. You can only add types derived from UnityEngine.Component onto game objects as components because they have to be… well, components, but your class is just a plain C# class.
So you need to modify your class to inherit from MonoBehaviour.
Im supposed to be creating a library thats meant to be implemented in another unity project as a dll and thought to try see if this shoddy base worked at first. So I have to derive from monobehaviour, thanks for the help
You’d be better off just making a Unity package instead.