Can't use my own package in an other project

Hello,

It’s my first question on this forum so sorry if it doesn’t follow the usual conventions.

I try to create a new package with Unity (SmartGamingLibrary) for one of my project and use it in an another project (called TestPackage) but can’t succeed to use it properly in my script.

I have a project called SmartGamingLibrary who follow the naming convention for a Unity Package.
There is below the architecture of the folder of the project and the Configuration class I try to use.

The content of package.json of my package SmartGamingLibrary

{
    "name": "com.smartgamingframework.smartgaminglibrary",
    "displayName": "Smart Gaming Library",
    "version": "0.0.1",
    "unity": "2020.3",
    "description": "A reusable library for creating game for smart device.",
    "author": {
        "name": "Vincent SORIN",
        "email": "vince.sorin@gmail.com.com"
    }
}

The content of Configuration.cs file

using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;

namespace SmartGamingLibrary.Utility
{
    public class Configuration
    {
         // some code
    }
}

When i create a new project called TestPackage and try to use my package previously created i have some trouble with the error message

Assets/Test.cs(2,7): error CS0246: The type or namespace name ‘SmartGamingLibrary’ could not be found (are you missing a using directive or an assembly reference?)

  • I have added successfully the package in the package manager view
  • I see my package in the projects views in the unity explorer
  • I also add a package.json to the root of my project to handle dependancies with my custom package
{
  "name": "MyUnityProject",
  "displayName": "My Unity Project",
  "version": "1.0.0",
  "dependencies": {
    "com.smartgamingframework.smartgaminglibrary": "0.0.1"
  }
}

And the code where i try to use the Configuration object from my custom package with the using instruction

using UnityEngine;
using SmartGamingLibrary.Utility;

public class Test : MonoBehaviour
{
    void Start()
    {
        Configuration config = new Configuration();
        Debug.Log("Configuration class loaded!");
    }
}

Sorry for the big message but if anyone had an idea on how to solve that, it will be really helpful.
Do not hesitate to ask more informations or picture if needed.

Thanks

According to the Finder window, you have overlooked the fact that your package will have to use Assembly Definition (.asmdef) files. Otherwise you cannot reference your package scripts in the project’s assembly definitions.

That is almost certainly why you can’t use your package code in the project.

That has no effect. There is no package.json for projects, only for packages.

The Package Manager maintains the Packages/manifest.json list (which packages are installed into the project) so there’s rarely any need to manually modify that either.

Do you require to use your package in this (no longer supported) version of Unity? Latest supported version is 2021.3 although not for much longer.

If the package is intended for the Asset Store, keep in mind that very very few developers actually buy & install packages to such outdated editor versions (data is in the publisher’s private section on this forum). The amount of testing and extra coding required to support older Unity versions typically far outweighs any benefits.

And just in case, the Asset Store uploader tool will only allow you to either a) upload a single custom package or b) upload the project’s contents but without any custom packages.

1 Like

Thanks, it was that. I think i have missed this part when reading the documentation for my first time using Unity. It’s working now :slight_smile:

Good to know, i remove it. I have looked at the manifest.json and have a better understanding on how the dependancies is handle.

Thanks for spotting this. As it was my first ever package, i didn’t notice this typo in the package.json and fix that now.
The package is only for internal use for now to help me for a personnal project, so no need to publish the package on Asset Store but let’s make it right at the start.

Thanks again for your help and your thoughts.