JuiceTin

I have custom 2D shaders built using the Amplify shader editor (Lit 2D), which work perfectly fine in Editor.

However in builds of the game, these materials are Pink on any Spine object, but work find on other objects.

Any reason this may be happening? I can't seem to find info anywhere.
JuiceTin
  • Posts: 13

Luke

Hello,

I'm sorry to hear you're having trouble with Spine objects in Unity; our Unity expert, Harald is on vacation at the moment.
Is there any way that you could post some screenshots of what's happening?
Luke

Luke
  • Posts: 140

JuiceTin

Sure, here's in editor:


And in build:


Note, the Unity ragdoll uses the same shader, which is a 2D lit sprite, and it works just fine in build.
JuiceTin
  • Posts: 13

Mario

Can younshare the shader code?
User avatar
Mario

Mario
  • Posts: 3242

JuiceTin

Of course!

Here's one of the shaders in the Amplify Editor (Equipped weapon).
Basically gets an RGB image and changes it's R/G/B colors.



And here is the shader code produced by the Amplify Editor:
https://pastebin.com/LWWRJUtt

Thanks!
JuiceTin
  • Posts: 13

Harald

Sorry for the delay.

How do you assign this material at the skeleton? Did you modify the material asset that is generated upon import of your skeleton data?
Are you using any special delayed loading mechanism, or Asset Bundles or the like?
Is everything working as expected when using e.g. the standard Spine/Skeleton shader instead of the Amplify shader?

Could you perhaps create a minimal Unity project that still shows this issue? You can send it as a zip package to contact@esotericsoftware.com (briefly mentioning this forum URL so that we know the context), then we can have a look at it.
User avatar
Harald

Harri
  • Posts: 4328

JuiceTin

Harald wrote:How do you assign this material at the skeleton?
The 4 body part materials are added onto the Atlas, which is then added into the SkeletonData. No other materials are used outside of those.
Harald wrote:Did you modify the material asset that is generated upon import of your skeleton data?
Nope created the new ones using Amplify.
Harald wrote:Are you using any special delayed loading mechanism, or Asset Bundles or the like?
Nope, and there are none in Graphics>Always Included/Preloaded shaders.
Harald wrote:Is everything working as expected when using e.g. the standard Spine/Skeleton shader instead of the Amplify shader?
Nope, I just switched the shaders to Spine/Skeleton and they still appear pink.

I will make a stripped down project and send it to that email, thanks!
JuiceTin
  • Posts: 13

Harald

JuiceTin wrote:Nope, I just switched the shaders to Spine/Skeleton and they still appear pink.
I will make a stripped down project and send it to that email, thanks!
Thanks for the additional info and for sending the reproduction project, we received everything. We will have a look at it and get back to you as soon as we've figured out what's going wrong.

---

The problem seems to be that your Material has no _MainTex property, then a call to material.mainTexture here in MaterialTextureLoader.Load throws an exception.

In general you can see such errors by building your project with settings Development Build and Script Debugging enabled. Then you can see an in-game development console displaying any errors.

To resolve this issue, you could either rename the texture property names in your shaders to the standardized name _MainTex, or perhaps Amplify allows you to declare a texture property as the main texture similar to Shader Lab:
https://docs.unity3d.com/ScriptReference/Material-mainTexture.html
User avatar
Harald

Harri
  • Posts: 4328

JuiceTin

Hi Herald, unfortunately that can't be the (only) issue, as that shader works everywhere else. It is only pink on spine.
Also, changing the materials to use Spine's default Spine/Skeleton shader still makes them pink.

Basically, any shader on spine always shows up pink, and any shader anywhere always works properly. You can change the materials currently on those spines to use the Spine/Skeleton shader to see what I mean.
JuiceTin
  • Posts: 13

Harald

When I change the shaders of all four materials of the skeletons to Spine/Skeleton no errors apprear and everything is displayed correctly, I don't receive any pink materials. Are you sure you changed all shaders and didn't leave some to your amplify shaders?
User avatar
Harald

Harri
  • Posts: 4328

JuiceTin

Ah right, I see I need all materials converted for it to work. BUT, Spine/Skeleton does not use 2D lighting.

I can't get any of lighting shaders to work, they all appear pink even after fixing the errors shown in the component.

Can you please show the proper way to get this working with 2D lit sprites? I think that may be the issue.
JuiceTin
  • Posts: 13

Harald

JuiceTin wrote:Ah right, I see I need all materials converted for it to work. BUT, Spine/Skeleton does not use 2D lighting.
This shader was not intended to be used, it just shows that a shader with the _MainTex property works. It is recommended that you fix your Amplify shader accordingly as described above, if you intended to use it originally.
JuiceTin wrote:I can't get any of lighting shaders to work, they all appear pink even after fixing the errors shown in the component.
Can you please show the proper way to get this working with 2D lit sprites? I think that may be the issue
Do you mean you don't get your Amplify shader to work after modifying the texture property name to _MainTex? Or do you mean that you don't get any of the lit Spine shaders to work? If you mean the latter, please note that you are using Universal Render Pipeline with a 2D Renderer asset, but I don't see the Spine URP Shaders UPM package installed in the package manager in your project. When using URP, standard pipeline shaders will not work, you need to add the Spine URP shaders package to your project. See here for more info on the Spine URP Shaders.

Before installing this package, please wait for the next soon to be released URP Spine shaders package, as you are using Unity 2021.2 and URP 12.1.2 which causes some known problems with the current Spine URP Shaders package. We will release an updated package later today if everything goes right.

---

Harald wrote:Before installing this package, please wait for the next soon to be released URP Spine shaders package, as you are using Unity 2021.2 and URP 12.1.2 which causes some known problems with the current Spine URP Shaders package. We will release an updated package later today if everything goes right.
The above bugfix update has just been committed and new Spine URP Shaders UPM 4.0 and 4.1-beta packages are available for download here as usual:
Spine Unity Download: Download
Feel free to download the UPM package now if you want to use Spine URP shaders with Unity 2021.2.
User avatar
Harald

Harri
  • Posts: 4328

JuiceTin

After a brief break from this, I finally came back and fixed it.

While _MainTex errors are perfectly harmless in game, they were hiding the real errors. Once I added an empty _MainTex texture to each shader, I started seeing errors that the shader requires the original texture to be placed in _MainTex. Fixing that solved the issue completely!

Odd that the _MainTex errors worked in editor, but hid the real errors that broke the build version.

Oh well, all fixed now, thanks Harald!
JuiceTin
  • Posts: 13

Harald

Glad to hear you've figured it out, thanks for letting us know!
User avatar
Harald

Harri
  • Posts: 4328

Harry_P

Hello!
Sorry for my English I use a translator.

I have a problem similar to the one described in this topic and also in this topic:
http://ru.esotericsoftware.com/forum/Unity-Custom-Shaders-build-problem-3757?p=18461&hilit=custom+shader+build#p18461

To my shame, I did not understand what I needed to do.
I am replacing the shader in the material of the spine object with a custom one.
I use a shader graph (screenshot attached). An important part of the mechanics in my game is that the image from an additional camera is rendered to an object with a spin animation.
Everything works good in the editor. But in builds of the game the spine object is pink. The shader works well both in the editor and in build with other (non-spine) objects.

I use the unity version 2021.1.15f1 and the spine version 4.0.64
You do not have the required permissions to view the files attached to this post.
Harry_P
  • Posts: 4

Harald

Did you try adding your shadergraph asset to the list of always included shaders under Project Settings - Graphics?
https://docs.unity3d.com/Manual/class-GraphicsSettings.html
If this does not resolve the problem, you need to ensure that the Material (which references the shader) is included in the build, e.g. by adding a disabled dummy-cube somewhere in an included scene which uses the Material.
User avatar
Harald

Harri
  • Posts: 4328

Harry_P

Harald wrote:Did you try adding your shadergraph asset to the list of always included shaders under Project Settings - Graphics?
https://docs.unity3d.com/Manual/class-GraphicsSettings.html
Yes, I did it. But there is no result.
Harald wrote:If this does not resolve the problem, you need to ensure that the Material (which references the shader) is included in the build, e.g. by adding a disabled dummy-cube somewhere in an included scene which uses the Material.
Yes, it is included in the build. Everything also works well for objects animated using the built-in unity animator or using other third-party animation programs. Problems arise only with the spine.
Harry_P
  • Posts: 4

Harald

Could you please send us a minimal Unity project that still demonstrates this problem? You can send it as a zip package to contact@esotericsoftware.com, briefly mentioning this forum thread URL so that we know the context. Then we can have a look at what's going wrong.

---

Thanks for sending the URL to the reproduction project via email, unfortunately you did not provide access privileges to download the file. Please either allow access for contact.esotericsoftware.com or provide read access for everyone.

---

The cause of the problem shows in the in-game development console as a logged error when you build your game with Development Build enabled:

MissingMainTexProperty.png


Your custom shader graph needs a Texture2D property with the reference name _MainTex, e.g. as shown in the following screenshot:

MissingMainTexProperty2.png
You do not have the required permissions to view the files attached to this post.
User avatar
Harald

Harri
  • Posts: 4328

Harry_P

For some reason, the shader stops working (even in the editor) if you specify the reference name of the texture that way.
Harry_P
  • Posts: 4

Harald

Could you please describe in more detail in which way it "stops working"? Do you see a pink material, do you receive any error messages at the Console window? Did you try reassigning the Texture at the spine obj_Material asset, likely the reference is no longer assigned since you changed the property name? Do you receive any error/warning messages displayed in the Inspector of the spine obj_Atlas asset?
User avatar
Harald

Harri
  • Posts: 4328

Harry_P

When I do this:
Harald wrote:Your custom shader graph needs a Texture2D property with the reference name _MainTex, e.g. as shown in the following screenshot:
and this:
Harald wrote: Did you try reassigning the Texture at the spine obj_Material asset, likely the reference is no longer assigned since you changed the property name?
Everything starts working as it should! Thank you so much!
Harry_P
  • Posts: 4

Harald

Glad to hear, thanks for getting back to us!

In case anyone wonders why reassignment is necessary after changing the Reference name: The Reference field is the actual property name (used in code and serialization), while Name seems to be only a the "pretty-print" editor display name. Thus when changing the Reference name string, the already saved assets see the new name _MainTex and re-initialize it to null (or a black or white fallback texture) since they don't find anything previously serialized (saved) under this name.
User avatar
Harald

Harri
  • Posts: 4328


Return to Unity