Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xlua中非UnityObject对象销毁问题 #1138

Open
yockguy opened this issue Apr 30, 2024 · 2 comments
Open

Xlua中非UnityObject对象销毁问题 #1138

yockguy opened this issue Apr 30, 2024 · 2 comments

Comments

@yockguy
Copy link

yockguy commented Apr 30, 2024

static bool ObjectValidCheck(object obj)
{
return (!(obj is UnityEngine.Object)) || ((obj as UnityEngine.Object) != null);
}
上面接口会每帧检查非UnityObject,进行销毁。如果非UnityObject对象,比如List的话,只能通过lua层置空,然后等C#的collectObject去销毁吗?能不能也有类似的检查方式去处理

@oOtroyOo
Copy link
Contributor

你这个接口,没看出来你指的什么“销毁”?
看似你写的只是与这个相同的功能
有的Unity对象,在C#为null..

我觉得你误解了销毁指的是 UnityObject.Destroy 还是 collect。
Destroy后的obj,这个obj访问时在C#中仍然是有对象值的,而不是单纯的null,是无法再次在引擎中使用的错误对象。终究还是要置空等collect。
这样的对象 在lua中如果写:

if obj then  -- 这里就会true,里面使用他就会出现异常
    ...
end

@chexiongsheng
Copy link
Collaborator

你没搞清楚这段代码的意思。
从C#语言的角度,就是没引用就释放。
UnityEngine.Object及其派生类有个特殊的状态:Destroyed,这段代码是加快这种状态对象的释放。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants