Search Unity

Package Manager packages support references to outside project

Discussion in 'Editor & General Support' started by roberto_sc, Jan 10, 2020.

  1. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    144
    I was surprised to find out that it is possible to have a package managed by Package Manager with references to the game project.

    I was moving some files from one project into a package to be used in a new project, using the Package Manager. I was following https://docs.unity3d.com/Manual/CustomPackages.html

    Some of these files have references to a plugin, so I had the idea to #ifdef the lines that use the plugin so if in the future someone decides to use the same plugin they can add a compilation directive to enable the code in the package. But then I thought it wouldn't work, because:

    1. maybe compilation directives from Player Preferences are not used when compiling packages;
    2. maybe packages are compiled before everyone else;
    3. the package has its own asmdef which doesn't point to the plugin.

    But it did work!

    Something doesn't look right here. What is happening?




    Example
    In my package I have a .cs file with the following:
    Code (CSharp):
    1. #if USE_ODIN_INSPECTOR
    2. using Sirenix.OdinInspector;
    3. #endif
    If I add the package using the Package Manager, set USE_ODIN_INSPECTOR in PlayerPreferences and add the plugin to my project everything works fine.

    This is probably the first post where someone is complaining because something is working.
     
  2. AndrewRyan

    AndrewRyan

    Joined:
    Apr 7, 2014
    Posts:
    19
    I assume this works because you made your package expect to reference the plugin in the project. This wouldn't otherwise work if those scripts were loosely contained in the project space.