Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by renderhjs · Jun 29, 2010 at 10:07 AM · editorcrashicon

Editor crash: EditorGUIUtility.Load in combination with GUI.drawTexture

What I want: Use icons (read bitmaps) within my Unity Editor Panel script so that I can display icon- instead text buttons.

What I am at: based on this board message: http://forum.unity3d.com/viewtopic.php?p=229676 I tried to replicate that but Unity crashes every time whenever I try it, I noticed also that often Unity doesn't really reload the script but caches it or just gets stuck.

Proof: Here is a screenshot of the project folder in Unity, booth icon png image and script are within the "Editor" folder.

alt text

This is the SoapEditor.cs script:

using UnityEditor; using UnityEngine; using System.Collections;

using System.Reflection; using System;

public class SoapEditor : EditorWindow { [MenuItem("Soap/Soap Editor #e")]//shift + e static void Init() { SoapEditor win = (SoapEditor)EditorWindow.GetWindowWithRect(typeof(SoapEditor),new Rect(0, 0, 120, 240),true); } void OnGUI() { Texture2D tex = (Texture2D)EditorGUIUtility.Load("EditorIcons.png"); GUI.DrawTexture(new Rect(0, 0, 16, 16), tex); } }

Any working example would be nice, because I can't even starting working on my editor Interface because unity keeps crashing at this point and even deletes scenes because of inconsistent backups. Thanks in advance,

Hendrik

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Mike 3 · Jun 29, 2010 at 10:27 AM

Most likely it's throwing an exception because something is null, and by the looks of your code, it's the Load bit - The function is for loading built in resources, and looks in a specific folder which isn't Assets/Editor

Instead, you should be using AssetDatabase.LoadAssetAtPath

This should stop it from crashing:

void OnGUI()
{
    Texture2D tex = AssetDatabase.LoadAssetAtPath("Assets/Editor/EditorIcons") as Texture2D;
    if (tex != null)
        GUI.DrawTexture(new Rect(0, 0, 16, 16), tex);
}

It takes a path relative to the project folder, and doesn't use extensions

Better still, you'd store tex once in your init function, then use it in OnGUI (though you'd still check for null in case it's been removed, etc - you can add a Debug.Log in an else if you want to make that clear)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jonas-echterhoff ♦♦ · Jun 29, 2010 at 05:44 PM 0
Share

AssetDatabase.LoadAssetAtPath is the correct function to use - but your sample won't work, as AssetDatabase.LoadAssetAtPath does not take a path relative to the Assets folder, but relative to the project folder, and it requires the file extension. So it should be AssetDatabase.LoadAssetAtPath("Assets/Editor/EditorIcons.png").

avatar image Mike 3 · Jun 29, 2010 at 05:51 PM 0
Share

Oh, true, changing it

avatar image renderhjs · Jul 05, 2010 at 11:56 PM 0
Share

Thanks guys, no it finally works for me. The whole Assets/Assets and from which point Unity counts the root or project folder is often confusing for me. I got it now working so that I can continue developing

avatar image Mike 3 · Jul 06, 2010 at 12:02 AM 0
Share

Nice to hear it :D could you mark the question as answered so it doesn't pop up once a week on the front page? :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

AssetPreview.GetMiniTypeThumbnail not working for custom scripts 0 Answers

Editor crashes after build on any platform 1 Answer

Unity Editor closes when loading my project 1 Answer

Access or remove background color of AssetPreview 2 Answers

Unity 4 Editor(?) main window is white on launch. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges