Search Unity

Bug No access to unity namespace

Discussion in 'Editor & General Support' started by hiaron123, Aug 2, 2022.

  1. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    I have a question about this one, I have never encountered this problem before, and I have no idea how to solve it. As you can see in the picture if I leave the Addressable_Spawn_selection script in the Asset file, it can use Unity.Engine.AddressableAssets without any problem. The issue is somehow my script in another folder cant access this script, it can only be accessed when I put both scripts in the same folder. Check the third picture. This allows my other script to access this script. But somehow the script then can no longer access Unity.Engine.AddressableAssets or Tmpro(TextmeshPro)(Check the fourth picture).





     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,819
    I feel as if that would indicate that it's being compiled into an assembly that doesn't have a reference to the other assemblies you're trying to use. Though based on the image of the directory, it doesn't look like you are.

    If you click on the script in question (when it's in the problem folder), what assembly does it say it's being compiled into?
     
  3. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    sorry, can you be more specific? I am a rookie, right now it's like if I place the script just in the asset folder, it can load the plugin namespace like TMpro(text mesh pro), but if I place the script inside a fold that is under the asset fold, it can no longer recognize the TMpro or Unity. Addressable
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,819
    Yes thank you, I understood you, which is why I'm trying to help.

    You can read about assemblies here: https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html

    When you click on a script you can see the assembly it's compiled into, like this example ripped from the docs:

    What do you see when you click on your script in the problematic folder?

    I'm going to assume there is an assembly definition file in your ARDKExamples folder. Is this a folder provided by an asset off the asset store?
     
    Last edited: Aug 2, 2022
  5. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    This is the normal one that I drop in asset file that can use everything
    upload_2022-8-2_14-18-0.png
    This is another one that doesn't work, but I have to create the script ni here because somehow if I didn't drop the script in here the ADRK script cant not access my script. It only works if I drop the script in here. But after dropping the script here it doesn't show recognize the plugin anymore like (TMpro )
     

    Attached Files:

  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,819
    Sigh. That's not what I asked you to do. Please read my post properly listen to what I say.
     
  7. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    sorry forgot to post the one with error,
    upload_2022-8-2_14-27-5.png upload_2022-8-2_14-27-17.png
     
  8. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    I opened the Definition file and it displays as below if I add something in the reference like "TMpro", UnityEngine.Addressable, will it work?
    upload_2022-8-2_14-31-42.png
     
  9. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,819
    Yes, so as I thought, you can see it's not in the default assembly. It's under it's own assembly ARDK-Examples.

    So you either need to modify the assembly definition in the ARDKExample folder to reference the addressables and TMPro assemblies, or make your own folder with your own assembly definition file, and reference the ARDK-Examples assembly, and any other assembly you need.

    And you should only modify the assembly definition through the inspector.
     
    Last edited: Aug 2, 2022
    Cubixrube and hiaron123 like this.
  10. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    ok thanks, I think I am able to use it now. You are a lifesaver!
     
    spiney199 likes this.
  11. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    I have encountered another problem. where I download a plugin and want to use the features. Last time I am able to add a reference because there is an assembly reference file, but this time there isn't one. So how can I access this in other DLL?
    upload_2022-8-4_13-39-59.png
    upload_2022-8-4_13-42-7.png
     
  12. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,819
    You should need to add a reference for any of Unity's internal assemblies.
     
  13. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    the thing is I try to add the reference like I always do, but this plugin doesn't have the assembly definition like others, I am able to use the code outside the ARDK file. Just not the script inside
     
  14. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,819
    Well it is in an assembly. Scripts that go into the special "Plugins" folder that don't already have an assembly go into the Assembly-Csharp-firstpass assembly. Is that not an option to reference? I always thought it didn't need to be referenced, as it was auto-referenced.

    Though honestly the numpty asset developer should be supplying their own assembly. And there's nothing stopping you from adding one yourself.
     
  15. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    upload_2022-8-4_15-51-13.png
    this is getting a little bit crazy, so I type ES3 and import it as a reference. In rider I press ALT+enter, and now the ES3 is green colour, so it is able to use the features. however, in the top left corner, you can see it's imported in solution instead of unity. In Unity, it still said that it doesn't know what it is
     
  16. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,819
    Well yes, Unity is the compiler, not Rider.

    Just introduce your own assembly definition and use that.
     
  17. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    The thing is if I add assembly definition to the plugin, a ton of errors popping up. Is there a way to reference the script without having assembly definition
     

    Attached Files:

  18. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,819
    Probably because the assembly you create needs references to other assemblies???
     
  19. hiaron123

    hiaron123

    Joined:
    Jul 18, 2019
    Posts:
    28
    upload_2022-8-4_18-8-38.png
    The thing is if I want to use this script I have to add an assembly to it, is there a way to use it without adding assembly?
     
  20. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,819
    No.

    The default Assembly-Csharp assembly has a reference, presumably, to the Assembly-Csharp-firstpass. For whatever reason you can't reference these directly, so when you use your own assemblies you can't reference the default assemblies.