1
\$\begingroup\$

I want to add a sample to an asset published on the Asset Store in Unity. Sample has a dependency on the netcode package. This causes users to get an error when they download it from the Asset Store. Actually, I write what needs to be done in the document, but those who try to use it without reading it encounter errors and make negative comments. How can I provide a solution for this issue?

\$\endgroup\$
2
  • \$\begingroup\$ If you install the package through the Package Manager, it should add the dependency to the manifest in the Packages folder inside the project directory. If I recall correctly, you can also explicitly declare dependencies in the Asset Store Tools when uploading the project. \$\endgroup\$
    – Kevin
    Commented Feb 21 at 22:35
  • \$\begingroup\$ The project I published in Asset Store has no dependencies. The sample I prepared just for demonstration has a netcode dependency. If this dependency belonged to the project, it would be as you said. However, for the sample, there is a dependency on a package that the project does not depend on. \$\endgroup\$
    – Atlas
    Commented Feb 22 at 11:50

1 Answer 1

0
\$\begingroup\$

You can use the Package Manager Scripting API to install a package.

You might want to prompt the user for this. For example:

const string PACKAGE_ID = "com.unity.netcode";
static ListRequest Request;
static void CheckForNetcodePackage() {
    Request = Client.List();    // Get a list of installed packages for this project.
    EditorApplication.update += Progress;
}

static void Progress() {
    if (Request.IsCompleted) {
        if (Request.Status == StatusCode.Success)
            // Check if the package is installed.
            bool found = false;
            foreach (var package in Request.Result) {
                if (package.packageId == PACKAGE_ID) {
                    found = true;
                    break;
                }
            }
            // If the package wasn't found, prompt the user to install it.
            if (!found) {
                string title = "Missing Netcode package";
                string message = $"The demo scene requires {PACKAGE_ID}. Install it?";
                if (EditorUtility.DisplayDialog(title, message, "Ok", "Cancel") {
                    Client.Add(PACKAGE_ID);
                }
            }
               
            EditorApplication.update -= Progress;
        }
    }
}

I haven't tested this code, so it may have typos or other mistakes, but it should be enough to get you most of the way there.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .