Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
0
Question by invicticide · May 02, 2010 at 04:10 PM · editoreditor-scriptingtexture2deditorwindow

EditorWindow loses Texture2D reference on scene change: how to handle?

I have a custom EditorWindow in which I'm implementing a Visio-like flowchart interface. To display the elements in the flowchart, my EditorWindow class just creates a new Texture2D(1, 1) in OnEnable(). That's all good and well, but if I switch to a new scene while the EditorWindow is open, I get spammed with errors that the Texture2D I'm trying to reference has been destroyed.

I guess it's curious that a Texture2D I've created programatically as a member of a class instance that's NOT being destroyed is getting destroyed by Unity without my knowledge, but more to the point... is there any way I can know that a) the asset has been destroyed, so I can recreate it, and/or b) the scene has been changed, so I can (again) recreate the asset?

Or am I just doing horrible violence to the editor in the first place? ^_^

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by elliott_d · Sep 09, 2021 at 06:45 PM

This is an old question, but it's still easy to get here with this problem, so I'll post my solution:

When you create the texture, set the hideFlags to DontSaveInEditor. If you do this, remember to also Destory the texture manually (in OnDestroy for the editor window).

Comment
Add comment · Show 1 · 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 BenSimGL · 23 hours ago 0
Share

Hi, thanks ! This is the solution, had the same issue and your answer solved it. (please Unity, don't delete Unity Answers, it's still relevant today !)

avatar image
0

Answer by N1nja · Aug 24, 2010 at 04:12 PM

The way I found to surpass this, is to load the texture OnEnable() but only if the variable is null, and to dispose of it OnDestroy() to avoid un-needed memory allocation... good luck!

Comment
Add comment · 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
0

Answer by Niall · Apr 26, 2011 at 04:57 PM

Why not create the texture AND save it to some temp location within your project? Then OnEnable(), you can read it in again if it has been lost in scene transition? I don't know where I got the idea, but I THINK if you create a Texture2D on the fly like that, it's actually created in your scene, but just never shows up, and is never saved.

Comment
Add comment · 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
0

Answer by imtrobin · Mar 19, 2015 at 07:37 AM

I'm facing similar, even though I saved the Texture2d reference in a static variable. I think its because the Texture2d is created inside the scene, and cleared when reloading.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Save/Attach content of editorWindow to a gameObject 1 Answer

how to stop reorderable list from passing Event value to the new element 1 Answer

Create a custom window and set his position on second screen 1 Answer

OnGui elements as objects? 2 Answers

Too much space between EditorGUILayout.SelectableLabel 2 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