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. Dismiss Notice

Question Unity Package code not global

Discussion in 'Asset Importing & Exporting' started by jag45, May 8, 2023.

  1. jag45

    jag45

    Joined:
    Feb 11, 2017
    Posts:
    10
    Hello,
    I recently created my own Unity package that I will be posting on the Unity Asset Store. I was required to add a namespace to the code before sending it off to be uploaded.
    When I locally import the class to another project I want to be able to access the Singleton from anywhere else in my project.

    But I am unable to access it. What do I need to do in order to access that script?

    I attached screenshots of:
    - JSON package
    - The main logger script that is to be used in my other project I uploaded the package to
    - my assembly definition for the package
    - and the code of how I am supposed to access the logger tool

    Please let me know what other information you might need or if this needs to go to a different forum.
     

    Attached Files:

  2. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    176
    Hi there,

    I'm not sure which part of the forum would be best suited for that question.
    Maybe in package management or assets and asset store... but maybe I can also help directly here.

    Looking at your screenshots, everything seems to be fine on the setup side.
    The asmdef has Auto Reference selected, your class is in a namespace, and you're trying to use it with the class name.
    Could it be that the file where you're trying to use the code is missing a
    using LogMachineController;
    at the top to make it find the LogMachine class in the new namespace?
     
  3. jag45

    jag45

    Joined:
    Feb 11, 2017
    Posts:
    10

    Hello! Thank you for the reply!
    I did have that but it didn't work (eventually it did)
    I needed an assemble def in my main code and needed to reference the packages assembly def. And now it works!
     
    bastien_humeau likes this.
  4. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    176
    Glad to hear that you solved it.

    Can I ask you to report a bug with your project whenever you have some time and post the bug ticket number here? Talking with the scripting team I think it should work without requiring an asmdef in your main code, so there may be something strange going on.