• Runtimes
  • Change Material Color at Runtime [UNITY5]

  • Modificato
Related Discussions
...

Hi,

I'm having trouble finding a way to change the color of an entire skeleton at runtime. The material that spine creates doesn't have a "color" attribute that I can find.

Am I missing something?

Spine skeletons use Vertex color. The correct way to handle this is to set Slot colors at runtime by iterating over the skeleton.Slots array

@Mitch wtf are you talking about.
Skeleton has a, r, g, b fields.
SkeletonRenderer uses it here: https://github.com/EsotericSoftware/spi ... er.cs#L267

@[cancellato]
Skeleton doesn't have a color field because the Color type is actually a Unity type, and Skeleton is in the generic C# runtime (which XNA/monogame also use). Instead, it has a r g b.
See here: https://github.com/EsotericSoftware/spi ... ton.cs#L43

You have to set the skeleton's a, r, g, b at runtime through code. We'll be adding an extension method for it soon. Like today, if PR gets merged.
So you can just say skeleton.SetColor( myUnityColor );

I'm high. Sorry. First night on ambien lol


Merged.

@[cancellato]

Thanks for the help, but how do I reference the skeleton? If I instantiate the skeleton from SkeletonData this creates a GameObject. Could you give me a quick example code of how I would reference the skeleton and its RGBA values?

Sorry for being such a plebian but code is not my forté.

skeleton is member variable of a SkeletonRenderer.

gameObject.GetComponent<SkeletonRenderer>().skeleton

Mitch ha scritto

skeleton is member variable of a SkeletonRenderer.

gameObject.GetComponent<SkeletonRenderer>().skeleton

Thanks so much Mitch. Is there any way to access this via unity javascript or does it need to be in C# to call?

You should learn C#.

srsly tho

var skeletonRenderer : SkeletonRenderer = gameObject.GetComponent("SkeletonRenderer");
skeletonRenderer.skeleton

Mitch ha scritto

You should learn C#.

srsly tho

var skeletonRenderer : SkeletonRenderer = gameObject.GetComponent("SkeletonRenderer");
skeletonRenderer.skeleton

I really need to but unfortunately I don't have the time to translate the whole project over to C# at this moment.

That reference is working now but now I'm having problems with the SkeletonAnimationInspector not being created when I move the runtime to the plugins folder. In order to import the namespace into the JS script, Unity requires that all the C# scripts be in the Plugins folder so that they are compiled first.

Here's the error:
Instance of SkeletonAnimationInspector couldn't be created. The script class needs to derive from ScriptableObject and be placed in the Assets/Editor folder.

Any workaround for this? I understand your support is focused on C# users so it's no big deal if it can't be helped. In the meantime, I'll continue :bang: :bang: :bang: until I have the time to sort this out.

All of the editor and inspector class files need to be in a folder named "Editor". This is already how the Spine runtime is arranged and it works out of the box.
But I'm not sure how it acts if the folders named "Editor" are inside the folder named "Plugins". You could move all the Editor folders to outside of the Plugins folder, maybe?

While Mitch isn't around yet, maybe you could investigate in that area. You might even find the fix yourself.

I think I've got it working now. Thanks.


Well now I'm getting the following error: Assets/Scripts/test.js(5,35): BCE0120: 'Spine.Skeleton.a' is inaccessible due to its protection level.

Here is the code for test.js:
function Start () {
var skeletonRenderer : SkeletonRenderer = gameObject.GetComponent("SkeletonRenderer");
skeletonRenderer.skeleton.a = 0.5;
}

The test.js script is attached to an instantiated SkeletonAnimation in the heirarchy. The SkeletonUtility/Editor folder and spine-unity/Editor folder are in their own separate folders while everything else is in the Assets/Plugins folder.

I'm so sad =(

Nate ha scritto

Look at the code. a is internal, A is public.

OMG Thank you! I'm an idiot.