Hello, I’m trying to access the SpriteSkin component in order to change the sprite name with the assigned bone’s name, but I noticed I cannot access anything from the SpriteSkin component.
Here is the code I am trying to run:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.U2D.Animation;
public class BonesUtilityEditor : EditorWindow
{
[MenuItem("Bones Utility/Rename Sprite")]
static void RenameSprite()
{
GameObject go = (Selection.activeObject as GameObject);
foreach (SpriteSkin sprite in go.GetComponentsInChildren<SpriteSkin>())
{
//Cannot access SpriteSkin
}
}
}
Is this how it’s supposed to be? How can I access which bone a sprite is attached to?
It doesnt appear that you are declaring the SpriteSkin class as a variable and then assigning it in Start or Awake. You are trying to access components in a Class from a different Class.
Well it is a component on the GameObject referenced in the script above and I am trying to access its own SpriteSkin component. I don’t get what I’m doing wrong.
Even if it is a component on the same gameobject as the script, you will have to reference it. Just like when you use an object’s Rigidbody2D, you have to declare it as a variable, assign it in start, and then you can access the properties of that component. Same thing for the Animator component, SpriteRender, etc.
I am referencing it in the foreach loop itself though.
Here, an example where I create a variable of type SpriteSkin but the issue persists, along another example with a component that works as intended.
Ahh, that makes sense. No idea then, sorry to waste your time. Here is a good post on working with different aspects of that library. Its all i got now.
No worries, was just a misunderstanding. Sadly, I have already looked into that but nothing regarding this.
I feel like it’s mostly a matter of waiting for Unity to realize this and change the library protection level. I could really use accessing it, would speed things up a ton!