jonnelyonne

Hello!

Just started using Spine with Unity3d and am encountering a very weird problem. The Mesh Renderer on my character seems to be instantiating with different types of materials. the material name is always the same, but sometimes it'll be with a (instance) at the back of the material name and sometimes it won't.

What this mainly affects is my ability to change the colors of the sprites at runtime. I noticed that I could change the colors when there was a (instance) but could not when there wasn't.

Any idea on what it could be?..
jonnelyonne
  • Mesajlar: 5

Nate

Strange. I'm not familiar with instanced materials, but the runtimes use renderer.sharedMaterials so I don't think it should be a problem. Which Unity runtime are you using? How are you changing the colors? Can you reproduce this behavior using the spineboy scene? Are you using the latest code from github? I committed Unity rendering changes a few hours ago.
Kullanıcı avatarı
Nate

Nate
  • Mesajlar: 12213

jonnelyonne

I'm using the Vanila Unity & C# runtimes.

basically, I'm changing the colors by referencing the MeshRenderer and setting the color again for every frame that changes it.

using UnityEngine;
using System.Collections;

public class Changingcolors : MonoBehaviour {
MeshRenderer myRenderer;

void Start () {
myRenderer = GetComponent<MeshRenderer>();
}

// Update is called once per frame
void Update () {
if(change)
{
myRenderer.material.color = new Color (red,green,blue,alpha);
red-=0.01f;
green -= 0.01f;
blue -= 0.01f;
alpha -= 0.01f;
}
}
}
This is a simplified form of it. The funny part is that if I call a different function using an if statement like below:
if (myRenderer.material.color.a <=0)


it will work as intended but the colors won't change if it is not an instanced material.

I am unable to reproduce this in the Spineboy or rather, this code doesn't work to change the colors in the Spineboy scene and the runtime I am using was downloaded last week.

If this is still not enough information, I can pass you my whole project folder through email?
jonnelyonne
  • Mesajlar: 5

jonnelyonne

More specifically, Friday last week.
jonnelyonne
  • Mesajlar: 5

Nate

To tint your whole skeleton use skeletonComponent.skeleton.R/G/B/A = 0 to 1.
Kullanıcı avatarı
Nate

Nate
  • Mesajlar: 12213

Pharan

Spine comes with a shader called Skeleton which uses vertex colors to apply tint. You need to use it (or any other vertex-lit premultipied-alpha-blend shader) so the colors animated in Spine works properly. And if you want to do it through code, you'd need to set skeletonComponent.skeleton's color fields. (R, G, B, A)

I think using code like: myRenderer.material.color only works for materials (and a shader) that have a color property on it. This is different from tinting via vertex colors and it's not very friendly to batching and usually isn't the preferred way to tint 2D stuff (That's nowadays anyway. Even Unity recently switched to using vertex colors for their text and 2D stuff because it's just more sensible for the most common cases).

I'm not sure how it would behave if you were using a material without a color property, or modifying it like that. Maybe that's why instances are popping up out of nowhere?

But I think sticking with vertex colors is the way to go. You shouldn't run into any problems unless you're in need of a very specific and complicated custom shader.
Kullanıcı avatarı
Pharan
  • Mesajlar: 5366

jonnelyonne

Thanks for the help! okay, I tried using the skeleton shader and adjusting colors using SkeletonComponent.Skeletons.R/G/B/A and the tinting is working like a charm!

But I'm running into another problem where my character seems to have a white background instead of a transparent one. any idea what the problem is?...

heres a snapshot just for reference:
http://i.imgur.com/RmxSWIm.png
jonnelyonne
  • Mesajlar: 5

Nate

You sure your atlas image is correct?
Kullanıcı avatarı
Nate

Nate
  • Mesajlar: 12213

jonnelyonne

Ah! Figured out the problem. The Atlas image was correct but there wasn't enough padding apparently and I had forgotten to check "Alpha is Transparency" in the import settings.

Feeling quite silly now actually... Thanks for the help!!
jonnelyonne
  • Mesajlar: 5


Dön Runtimes