- Home /
Warning: Type conflicts with the imported type
I can't wrap my head around this warning, and I'm not sure if it's actually important but I'm trying to find out. I've scoured the forums and couldn't find a solution that works in my case, though it's likely that's due to my lack of understanding of the issue. From what I understand, the error is usually caused when referencing the containing class when declaring a variable, but this class doesn't reference itself.
Capitalization/renaming was mentioned a bunch but if I rename the struct I need to rename the list, etc, so that doesn't work as a solution.
Any help pointing me towards a solution would be seriously appreciated, everything in the project works fine but having warnings is never a nice thing, especially without understanding them. Here's the warning and the class throwing the errors:
'The type 'DevShortcutItem' in '/Users/Orion/Game Development/Parabola/Assets/Parabola/Code/Developer/DevShortcutDisplay.cs' conflicts with the imported type 'DevShortcutItem' in 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/Users/Orion/Game Development/Parabola/Assets/Parabola/Code/Developer/DevShortcutDisplay.cs'. [Assembly-CSharp-Editor]'
public class DevShortcutDisplay : MonoBehaviour
{
// Some Other Variables
public List<DevShortcutItem> Shortcuts = new List<DevShortcutItem>();
Rect windowRect = new Rect(80, 55, 250, 240);
List<string> shortcutString;
void Start()
{
shortcutString = new List<string>();
foreach (DevShortcutItem item in Shortcuts)
{
shortcutString.Add(Reveal + " + '" + item.Key + "' to " + item.Description);
}
}
void OnGUI()
{
GUI.backgroundColor = Color.black;
if (!HiddenByDefault || Input.GetKey(Reveal))
{
GUI.skin.font = DefaultFont;
windowRect = GUILayout.Window(0, windowRect, CreateWindow, "Shortcuts");
}
}
void CreateWindow(int windowID)
{
for (int i = 0; i < Shortcuts.Count; i++)
{
if (Input.GetKey(Shortcuts[i].Key))
{
GUI.skin.font = HighlightFont;
GUILayout.Label(shortcutString[i]);
Shortcuts[i].Event.Invoke();
}
else
{
GUI.skin.font = DefaultFont;
GUILayout.Label(shortcutString[i]);
}
}
}
}
[Serializable]
public struct DevShortcutItem
{
public KeyCode Key;
public string Description;
public UnityEvent Event;
}
Have you tried moving the DevShortcutItem struct to a separate C# file?
Edit: Check this thread https://stackoverflow.com/questions/8073806/warning-the-type-x-in-y-cs-conflicts-with-the-imported-type-x-in-z-dll
It seems like there may be a duplicate of the assembly somewhere in your project
I did, it was originally in its own file but I moved it into the same file to see if it would make a difference. I get the same error if it's together or separated.
Answer by PizzaPie · Dec 06, 2017 at 05:32 PM
You have two definitions of the same Type (class), even though they are on different Assemblies (Assembly-CSharp(runtime) and Assembly-CSharp-Editor(editor time)) they are both "wrapped" in the default(root) namespace (for each Assembly) meaning they don't need specific instructions to be accessed (counter ex using UnityEngine.UI to access UI elements).
Now on editor time Unity loads automatically both (while it loads only first one on runtime) thus it stumbles on two definitions, to resolve it, it chooses to use the one of Assembly-CSharp-Editor because it knows that you work on edit time.
Anyway to fix it you need to define which one you want it to use. The easiest way to do so would be to change the name of one of the two classes, or wrap one and or both on different namespaces.
Of course you can ignore it if you don't want to use the definitions from Runtime on edit time (bad practice).
Cheers.
I'm still slightly confused as to how I change the name of one of the two classes, I don't understand how I have two definitions of the class, I have the struct named DevShortcutItem and then I use that as the type in my list. In what way can I change the name of one of the classes?
I did realize after your description that I could move the struct into the DevShortcutDisplay class which stops the error, and fortunately this struct isn't going to be used anywhere else, but other times I'm sure that won't be the case. If I wanted to keep the struct outside the class, how would I go about avoiding this issue in the future?
You must have a definition of the struct (my bad that i said class, but it s pretty much the same in this occasion) somewhere else. Now one (according to the warning log) is inside a .cs file located inside an Editor folder while the other .cs that contains the second definition is not, thats why it is a warning and not an error. To find it go to your IDE and perform a definition search for DevShortcutItem it should find both locations. As on how to change the name
//from
public struct DevShortcutItem
//change to
public struct DevShortcutItemStuct //or anything you don't already use
Weird, there's actually no other struct definition in the project, I checked in VS and it still had the error, I moved the struct into the DevShortcutDisplay class which fixed it, as expected, but for some reason, after moving it back out into a separate class the warning went away. So it looks like it was actually some sort of bug. Hopefully it's always as simple to fix.
Thanks for the help and the better explanation of what the warning is actually talking about.
Still can't get my head around all that namespace thing, but I´ve managed to get it to work! That and the old Unity restart did the trick. In my case I was tryng to work with Vuforia from a package.
Answer by faulknermano · Feb 17, 2019 at 09:44 PM
I got this error for a class that I was modifying and was referencing in other scripts. What I did was restart Unity and the error went away. I wonder if it had something to do with one assembly (editor perhaps?) compiling and the other was not.
This fixed my problem too! Thanks. I just had to restart VSCode and Unity
Answer by Bunny83 · Dec 06, 2017 at 06:00 PM
I guess you created a build of your game inside your assets folder. Never do this. If you want to create a build it should be outside the Assets folder of your project.
You guessed wrong. The problem I had was that the BurstCompileAttribute was imported as normal through the Burst package. But I didn't define it myself anywhere (of course). Saving and reloading the project fixed it though, so I'm guessing Visual Studio Code did something dumb like cache the name before AND after I imported it.
Answer by BradLeeD · Apr 07, 2018 at 01:19 PM
Sometimes I get this error - it's a bug though in my case.. All I have to do to fix it is change the first letter of my script file name from upper case to lowercase in the Project window.. and then change the name / class accordingly in my script. Idk why this happens.. just does - and Idk why this fix works .. but in my case it always does. - Otherwise you probably have 2 copies of the same script / same class name for 2 diff scripts. Hope this helps.
Answer by DevilCult · Oct 07, 2019 at 01:24 AM
Just got this error myself, its just because visual studio stayed open with scripts in it while i upgraded unity version. Close visual studio, restart unity, no more error.
Visual Studio Community or Visual Studio Code? I get the error with VS Code but I never get it with VS Community.