(this is from a custom TextMeshPro shader in our project).
Now, with TMPro being a “package”, I can’t get that include line to work anymore.
I tried #include "TMPro_Properties.cginc" in the hope that somehow Unity is doing the same as for its internal shader includes for packages as well, but no luck.
So what is the recommended way to get my custom shader to work again? The TextMeshPro package is installed somewhere on the system, depending on user settings, etc., so what am I supposed to include so this shader works on any machine like before?
Copy the shader and include it in your project files. Not 100% sure, but the shader compiler first looks for the include files in the location of the shader. Either way, if you’re using a custom .cginc you would have to include it in your assets, as any updates to the package would overwrite it.
This is possible but this is yet to be documented. You have an example in the postprocessing package:
So the gist of it is to create a static function that adds new include paths for the shader compiler using the ShaderIncludePath attribute:
using System.Linq;
using UnityEngine;
using System.IO;
namespace YourNamespace
{
static class TmpShaderIncludePath
{
[ShaderIncludePath]
public static string[] GetPaths()
{
// This will add the text mesh pro package root path to the list of
// shader compiler include paths. Adapt to go deeper in the package
// folder tree.
return new string [] {Path.GetFullPath("Packages/com.unity.textmeshpro")};
}
}
}
I’ve reached the TextMeshPro team so they add the shader include path automatically without users having to do it themselves.
Yes, we had the TMP package in the project before, but since Unity is moving in that “package management for everything” direction I’d rather give input on things that are tricky now than just work around
unfortunately that only works with the simplest of shaders, since usually cgincs contain more necessary cgincs. So we’re back to (1) with that
again, this goes kinda against the idea of the whole Package Manager for something where I want to extend, not replace, existing functionality
@okcompute_unity Thanks! That sounds great and very useful. Then how would I, without knowing where TMPro lives on disk, find the right include pathes? For me, the com.unity.textmeshpro folder in Packages does contain some folders, but all are empty. Is there some softlink magic going on internally?
@fherbst Yes, the package manager sits on top of a virtual file system that resolved the correct absolute path internally. This rule apply to any assets located in a package. You can reach for anything inside a package though the logical /Packages/<package name> root path.
The Package Manager is a very useful tool that can provide even more future interesting features like dependency control but it would be great if it could follow a more transparent approach when deploying packages.