Unity 编辑器 leak
来源:互联网 发布:淘宝装修软件哪个好 编辑:程序博客网 时间:2024/05/22 03:40
Just for the record.
- In Edit mode nothing is executed (obvious, isn’t it?)
- When entering play mode: Awake(), OnEnable(), Start()
- When stopping: OnDisable(), Destroy()
The leak
I want to create a Material in my code. With knowledge of how MonoBehaviour is living I’ve decided to do it in OnEnable() method and destroy it in OnDisable() method. The reason is simple: I don’t want to reload the scene when I’ll change something that will affect the material code. This +should be enough:
Do you want to guess what will happen after I put this to game object and hit CTRL + S (Save Scene-)?
Bravo! Here it is!
If I think right this will happen every time when Unity will find dynamically created Material that is not attached to any Renderer component. Unity cannot verify if you’ll destroy the object so it fights back with this information above. So there must be a trick to tell Unity that I know what I am doing and I will clean my resources, right?
This magic formula is called HideFlags.DontSave. According to documentation “The object will not be saved to the scene. It will not be destroyed when a new scene is loaded“. So this is giving the responsibility for destroying the object back to us. Let’s try it:
And that’s it! No more messages about leaking objects! But be careful to always remove your objects by DestroyImmediate(). Not doing so may break Unity for someone who is using your code.
- Unity 编辑器 leak
- Unity编辑器
- unity编辑器
- Unity-Unity编辑器Part1
- Unity-Unity编辑器Part2
- Unity-Unity编辑器Part3
- Unity-Unity编辑器Part4
- Unity-Unity编辑器Part5
- [Unity编辑器]自定义编辑器界面
- unity编辑器制作(一)
- Unity(1) 编辑器结构
- unity编辑器扩展
- unity编辑器设备丢失
- 【Unity】编辑器属性
- unity编辑器学习
- Unity的编辑器使用
- unity编辑器拓展
- Unity编辑器扩展
- 2013 腾讯一面面试题
- JQuery插件最佳实践
- web 系统权限控制
- MySql安装出错
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
- Unity 编辑器 leak
- C++拷贝构造函数详解
- 【数据结构】——排序算法——3.1、选择排序
- 浅谈基于流媒体转发技术的IP数字监控系统
- 理解Java中static、final用法
- 微信聊天界面
- 1032. 挖掘机技术哪家强
- poj1083,nyoj220推桌子 贪心
- Fresco介绍 - 一个新的android图片加载库