passerph 发表于 2014-3-26 23:26

困扰了两天的问题,关于GetComponent出的诡异错误...

我在一个Scene里创建了多个ngui做的界面,做成了prefab,用的时候通过销毁和创建实现界面切换,但是每个界面只有首次进入的时候是正确的,destroy后再创建,脚本就必会报错:
The object of type 'UISprite' has been destroyed but you are still trying to access it.Your script should either check if it is null or you should not destroy the object.
经过测试,发现销毁后,再创建的物件上,不能使用 gameobject.GetComponent<UISprite>();来获取组件,否则必报上面的错误,不知道哪位大哥大姐遇到过类似的问题,想求个解决方案,实在不行解释下原因也好。多谢,多谢!!


-----------------------------------------------------------------------------------------------------
从来没哟这么期待过有人回帖。。。。

thebat 发表于 2014-3-28 09:05

不能setactive吗?为啥非要destroy

lion027 发表于 2014-4-2 11:00

应该是插件的版本老了下个新的   我昨天用的tk2d 也抱同样的错   

cl535657573 发表于 2014-4-29 16:48

你的prefab上面有UISprite吗?

KyiO 发表于 2014-4-30 09:10

类型的对象UISprite'已被破坏,但你仍然试图访问it.Your脚本应该要么检查它是否为null,或者你不应该销毁对象。

pincers 发表于 2017-3-12 11:27

好帖就是要顶

xconer 发表于 2017-3-12 12:01

说的非常好

箫尧 发表于 2017-3-12 11:51

很好哦

牵生活欠自己 发表于 2017-3-12 11:23

不错不错

wsffx13 发表于 2017-3-12 11:34

LZ真是人才
页: [1] 2 3 4 5
查看完整版本: 困扰了两天的问题,关于GetComponent出的诡异错误...