In my asset published on Asset Store I use the AI Navigation package and I have to use the following code:
#if UNITY_2022_2_OR_NEWER
using Unity.AI.Navigation;
#endif
The issue is that if the user has not already installed the new AI Navigation package before importing the asset, Unity raises an error and does not activate the editor until the package is installed.
I’ve searched a lot but haven’t found any way to prevent the condition from being executed if the package is not present.
I tried adding the InitializaOnLoad method in which I load all the installed packages into a list and compare them with the “com.unity.ai.navigation” string, the code does its job but only after the editor has been loaded.
It is not executed during import because the error is generated before the code runs.
In the error message it is clear what the problem is, and the user will certainly be able to fix the problem, but I would prefer to show a message on the screen that suggests installing the package.
Is there a way to not have the directive executed if the Navigation package is not installed, or alternatively to catch the error when importing my package?
https://discussions.unity.com/t/935897/3
You can have .unitypackage files specify UPM dependencies and the editor will prompt users to install (or skip) them before import.
Unfortunately I just published the package but I couldn’t use the suggested functionality as I didn’t find Navigation AI among the dependencies.
I think it’s because I used a version older than 2022.2 to upload the package.
As I said, I have now published without being able to verify the existence of the package but I would be happy to find a solution.
I’ll take a look at your second tip.