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

Scripts from local package cannot find scripts in Assets

Discussion in 'Scripting' started by hiphish, Oct 25, 2021.

  1. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Hello,

    I have a setup where some scripts are stored under
    Assets/Grid Framework/Plugins/
    and I need reference these scripts from with a local package stored under
    Packages/com.hiphish.grid-framework.samples/
    . Here is what one of the package scripts looks like:

    Code (CSharp):
    1. using UnityEngine;
    2. using GridFramework.Renderers.Rectangular;
    3.  
    4. namespace GridFrameworkSamples.Endless2D {
    5.    // ...
    6. }
    The first
    using
    statement works, but the other one raises a compile-time error that the
    GridFramework.Renderers
    namespace cannot be found. That namespace definitely does exist, I can create instances of its classes in the editor without issue. My understanding is that the package needs to be told to reference the assemblies it needs to use, but I have no idea how to do that for a namespace that is not inside another package but part of the project.

    Here is what I am trying to achieve: Grid Framework is a plugin I'm selling on the Asset Store and I want to make usage examples available as a Git package. Originally I wanted to make the entire Grid Framework a package, but it is impossible to upload anything outside the Assets folder to the Asset Store. So the next best thing to do would be to at least move the examples into a package; people would first install Grid Framework, and if they want examples they can install the extra package. Why not include the examples directly? Because if I do that then the example scripts and textures end up spamming the user's project.

    I have also Playmaker and Vectrosity support and I had no issue referencing their packages. Somehow it works for them.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    hiphish likes this.
  3. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Thank you, that link led me down the right path. For anyone reading this in the future: I have organized the main files as follows:

    Code (csharp):
    1.  
    2. Assets/Grid Framework/
    3. ├── Editor
    4. │   └── ...
    5. └── Runtime
    6.     ├── ...
    7.     └── com.hiphish.grid-framework.Runtime.asmdef
    8.  
    I have omitted the metadata files. The important point is to have the assembly definition file. I put it inside the Runtime directory (which contains all the business logic) because I don't want to bloat it with editor scripts. I might add a separate assembly for the editor scripts if it becomes necessary. The name is unimportant, the location is what matters. The default settings in the assembly definition are sufficient (make sure it is auto-referenced). I also set the root namespace to GridFramework, no idea is that is actually necessary.

    Now comes the second step: inside the package (which contains the samples in my case) there should already be an assembly definition. This assembly definition must reference the previously created assembly definition. This will allow the samples to find all the class definitions.
     
    Kurt-Dekker likes this.