Hello,
i need to create prefabs for many items, so i chose to use a script to do that:
[MenuItem("Assets/Generate WorldArt Sprite Prefab")]
static void Execute() {
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
string destPath = string.Format("Assets/Prefabs/worldart/{0}.prefab",Path.GetFileNameWithoutExtension(path));
Texture2D tex = (Texture2D)Selection.activeObject;
Sprite s = Sprite.Create(tex, new Rect(0,0,64,64), new Vector2(0,0));
GameObject go = new GameObject();
SpriteRenderer sr = go.AddComponent<SpriteRenderer>();
sr.sprite = s;
PrefabUtility.CreatePrefab(destPath, go);
}
The problem is that, after running the script, i find the Prefab to be without the sprite but with the spriterenderer, as you can see below.
I followed the script with VS debugger, and i’m not casting anything to null.
Does anyone know what’s happening?
Thanks a lot!