Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Button onClick.AddListener definition not found

Discussion in 'Scripting' started by Gorjeck, Jul 30, 2020.

  1. Gorjeck

    Gorjeck

    Joined:
    Jun 22, 2020
    Posts:
    2
    Hello,

    I'm having my own librarry that I'm use in my unity project. Im referencing both UnityEngine end UI dll :
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    I'm trying to implement some UI element from this library :
    Code (CSharp):
    1. GameObject startButton = GameObject.Find("StartGameButton");
    2. startButton.GetComponent<Button>().onClick.AddListener(MyFunction);
    And I'm getting the following error :
    Note that this code work in my unity project.

    Thanks
     
  2. Cyber-Dog

    Cyber-Dog

    Joined:
    Sep 12, 2018
    Posts:
    265
    Hey,

    How is your library setup? Have you tried calling these functions from a script inside your project?

    I'm surprised you didn't have issued building a library, every-time I have built a dll for Unity it has had to exclude anything Unity related and just work of the .Net framework.
     
  3. Gorjeck

    Gorjeck

    Joined:
    Jun 22, 2020
    Posts:
    2
    Hi,

    I'm referencing both UnityEngine.dll from /Applications/Unity/Hub/Editor/2020.1.0f1
    And UnityEngine.UI from my unity app which is /path/to/app/Library/ScriptAssemblies/UnityEngine.UI.dll

    I have actually have 2 libraries, one that I build and move the library directly to the Assets folder and one that I load after runtime using Assembly.LoadFrom("path/to/dll");

    Both work but now I have this problem.
     
  4. Cyber-Dog

    Cyber-Dog

    Joined:
    Sep 12, 2018
    Posts:
    265
    I always had issues trying to build a library reliant on Unity. These days if its a library I am building, I will keep it to just dot net framework.

    Sorry, that's not an answer to your problem. But tbh, your better of just creating scripts.

    Is its because your trying to make an asset for the unity store? If that's the case, its another reason to not build with unity DLLs. Someone who purchases your asset would not be able to make any version change fixes.
     
unityunity