- Home /
Unity 5 Error: The imported type is defined multiple times
Hi
After upgrading my Project, which is based on the Unity Bootcamp Photon Demo, I have got these two errors:
The imported type ExitGames.Client.Photon.IPhotonPeerListener' is defined multiple times The imported type
ExitGames.Client.Photon.PhotonPeer' is defined multiple times
I have reimported the script from the assets store, but the errors are still the same.
Anybody an idea?
Try searching your assets folder for source files containing "IPhotonPeerListener". You'll probably find it's defined multiple times.
Thats the code, which is causing the error:
namespace ExitGames.Client.Photon.LoadBalancing
{
using System;
using System.Collections;
using System.Collections.Generic;
using ExitGames.Client.Photon;
using ExitGames.Client.Photon.Lite;
/// <summary>
/// A LoadbalancingPeer provides the operations and enum definitions needed to use the loadbalancing server application which is also used in Photon Cloud.
/// </summary>
/// <remarks>
/// The LoadBalancingPeer does not keep a state, ins$$anonymous$$d this is done by a LoadBalancingClient.
/// </remarks>
public class LoadBalancingPeer : PhotonPeer
{
/// <summary>
/// Creates a Peer with selected connection protocol.
/// </summary>
/// <remarks>Each connection protocol has it's own default networking ports for Photon.</remarks>
/// <param name="protocolType">The preferred option is UDP.</param>
public LoadBalancingPeer(ConnectionProtocol protocolType) : base(protocolType)
{
// this does not require a Listener, so:
// make sure to set this.Listener before using a peer!
}
/// <summary>
/// Creates a Peer with default connection protocol (UDP).
/// </summary>
public LoadBalancingPeer(IPhotonPeerListener listener, ConnectionProtocol protocolType) : base(listener, protocolType)
{
}
...
How can I fix now this Error? Should I delet one of these functions?
Yes, Bonfire Boy does. You most likely have two copies of the code in your project, in different folders. You need to find the older one (presumably it was there before your upgrade) and delete it.
That's not what I said to search for. The type you've got multiply defined is IPhotonPeerListener, so that's what you should search for, within files (I'm not talking about about a filename search). Could be in DLLs as well as source files.
Or you could try removing the Photon stuff until it works (and then reimporting the latest if it starts complaining that it can't find things as opposed to finding them too many times).
Answer by NerdClown · Oct 13, 2015 at 11:58 AM
Okay, same problem just occurred for us today. Not sure it's the same thing, but this is what the case was for us:
Having upgraded from unity four to five, I wanted to bring in a new version of Photon as well. I deleted the "Photon Unity Networking" folder, imported the new version and was then told that I had multiple definitions of IPhotonPeerListener and PhotonPeer just as OP had.
After some investigation, it turned out that it had to do with the Photon3Unity3d.dll file in the Assets/Plugins folder, which I had neglected to delete. In stead of overwriting it (which I'd expect) Unity had somehow kept both files, renaming the new one (by adding a one at the end):
Directory of E:\UnityProjects\NS15_u5_2\Assets\Plugins
17/09/2015 15:02 140,288 Photon3Unity3D 1.dll
05/05/2015 09:40 146,432 Photon3Unity3D.dll
Unsurprising this left us with same namespace/class declared more than once. Solution was getting rid of both files and importing the .dll again.
I have the same problem with one of my delegates. I rename the delegate and the error goes away, until I restart Unity and the newly renamed delegate pops up as an error again. Annoying. I definitely don't have the same function defined twice. It's some weird Unity issue.
Answer by Influnza · Nov 06, 2017 at 01:12 AM
I just had a similar problem with importing Newtonsoft.Json.JsonReader type in Unity 2017. It turned out that I imported an asset that pulled the second Newtonsoft.Json.dll and caused the error, because I already had it in my project. I had to look into detailed logs to see the paths where the type was defined. It would be easier if they were just exposed in the console.
I had the same issue with Newtonsoft.Json
I simply went to my project window inside of Unity, searched for Newtonsoft.Json, deleted all of the .dll files, then reimported the plugin.
FIXED
Answer by augivision · Mar 28, 2018 at 09:27 PM
I had the same issue.
I suggest:
Deleting all plugins and folders related to plugins and then redownloading them all.
Export your project as a unity package, then import that package into a completely new project, but only import the stuff you absolutely need. You want to avoid all plugins and store-bought addons. Once it is imported you should reinstall any plugins or addons that you had. Should work fine now.
Again, only import the bare necessities (like your models, custom scripts, etc), then redownload or reinstall any additional unity packages or plugins.
This worked for me, I hope it helps you.
Your answer
Follow this Question
Related Questions
Unity 5.6 upgrade pains 0 Answers
Sound files not working [Unity 5.1] 0 Answers
mac unity fbx import error 0 Answers