- Home /
Assign GameObject Icons, More Than Just One at a Time?
Ok, I can't believe I have to select each GameObject separately to assign multiple objects the same icon. How can I achieve this? I have over 200 camera labels that were messed up with the Unity 5 upgrade, and I'd like to avoid taking the time just to assign them the same icon.
Much thanks for any help.
I guess you can do it by code but that would require some time to set up.
For example, you can add the icons using Resources to an UI object. Then via code, you set the camera labels to this UI object.
It's still time consu$$anonymous$$g though. But if you do it right, the next time something like this happens, the code will take care of it since it takes the files directly from the Resources folder.
Did you find a solution to this?. Im having the same problem, I need to change the icon to ~300 gameobjects and I can't believe that I have to do it one at a time.
I never did. I spent half a day looking for a solution, then decided to just plow through it. Grab some coffee or a beer and just get through it. :( Hopefully they're listening!
Thank you for taking the time to answer, I'm afraid I'll have to do the same.
Answer by ShawnFeatherly · Sep 08, 2016 at 09:42 PM
Found a script that'll assign the icon for one gameobject at: http://forum.unity3d.com/threads/editor-script-to-set-icons-impossible.187975/ It uses reflection to get the job done.
public static void AssignIcon(GameObject g)
{
Texture2D tex = UnityEditor.EditorGUIUtility.IconContent("sv_label_0").image as Texture2D;
Type editorGUIUtilityType = typeof(UnityEditor.EditorGUIUtility);
System.Reflection.BindingFlags bindingFlags = System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic;
object[] args = new object[] { g, tex };
editorGUIUtilityType.InvokeMember("SetIconForObject", bindingFlags, null, null, args);
}
Tried this code to apply an icon dynamically for scriptable objects of the same class depending of their content. Apparently its not possible : https://www.reddit.com/r/Unity3D/comments/g13odm/unique_icon_to_every_specific_scriptable_object/
This code changed the default icon of all the scriptable objects instances of the same class.