Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Using GetComponent with an interface within a DLL file

Discussion in 'Scripting' started by Talthilas, Jun 29, 2016.

  1. Talthilas

    Talthilas

    Joined:
    Apr 1, 2014
    Posts:
    44
    Hi,

    I've been using gameObject.GetComponent<MyInterface>() throughout my project with no problems.

    Recently I've been moving a bunch of code to DLL files and have noticed that visual studio highlights the above GetComponent code (during design time) as an error stating something along the lines of "cannot implicity cast MyInterface to Component". The exact same code works in my project, but not in the DLL file.

    Can you use GetComponent with interfaces in DLL files? If so, how do I get it to work?

    Thanks.
     
  2. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    What version of Unity are you using?
     
  3. Talthilas

    Talthilas

    Joined:
    Apr 1, 2014
    Posts:
    44
    v5.3.4f1 Personal. I think I just fixed it. I added the UnityEditor.dll, UnityEngine.Networking.dll, UnityEngine.UI.dll references to my library project, and I also removed and added UnityEngine.dll again. In addition, I am referencing the DLL's located in my Project/Library folder instead of the ProgramFiles\Unity.... etc folder that the Unity docs tell you to use. Don't know why its working now, but I'm not complaining!
     
  4. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    You probably had an old UnityEngine.dll that didn't support interfaces.