首页 > 其他分享 >unity UnityEngine.Object 和 == ?. ??.的关系。

unity UnityEngine.Object 和 == ?. ??.的关系。

时间:2023-02-01 20:23:32浏览次数:36  
标签:UnityEngine object since Object will unity null

参考:

https://answers.unity.com/questions/1705335/how-can-throw-missing-reference-exception-this-gam.html

https://docs.unity3d.com/ScriptReference/Object.html

 

结论:

1.UnityEngine.Object是覆盖写了System.object的==和 != 

2.但是 ?. 和 ??.没有覆写,使用这两个是不安全的

3.关键概念:在UnityEngine层面的Fake Null。   UnityEngine.Object和nativeCode要有counterpart对应关联,并且说明这个Unity资源是可安全使用的,当Object ==null表示不能用并且交给GC去处理了。

                     What the method does is actually destroying the object on the native side and mark the managed wrapper object as "being destroyed". Such an object will essentially pretend that it is null since it's no longer useable since the native counterpart is missing. That fake null object will eventually be garbage collected once all references to it are gone.

 

4.网址内一个典型的例子:

  

  

 1 // Object also creates a fake null object because it has no native counterpart
 2  MyMonoBehaviour obj = new MyMonoBehaviour();
 3  
 4  // obj==null will be evaluated to true, since it is fake null. Since the variable type is
 5  // UnityEngine.Object derived the custom == operator will be used.
 6  if (obj == null)
 7  
 8  // o==null will NOT evaluate to true since operators are not virtual methods.
 9  // In t$$anonymous$$s case the System,Object == operator will be used.
10  object o = obj;
11  if (o == null)

 

标签:UnityEngine,object,since,Object,will,unity,null
From: https://www.cnblogs.com/sun-shadow/p/17084056.html

相关文章

  • Python中报“TypeError: 'int' object is not callable”错误的解决办法
    当时就想用sum()函数求和发现之前 “sum” 这个关键字被当变量名定义过了,然后我试着把自己自定义的变量都给删除了,删除之后再次试了一下,发现可以了,果然是sum()函数被之......
  • centos6报错ls: error while loading shared libraries: libc.so.6: cannot open shar
    生产环境由于误删了libc-2.12.so和libc.so.6文件导致报错如下:现在复现此过程:1.移除这2个文件mvlibc-2.12.solibc.so.6/opt/此时再次执行命令就会报错,错误信息如下:ls:er......
  • java:Object是不是泛型?
    我们知道Object是所有类型的父类。可以把任意类型转换成Object来存储。那么Object是不是泛型?当我们需要定义一个变量,用来接收任意类型的变量时,可以不可以将该参数定义为Obj......
  • 关于unity使用导入 .unitypackage报错的解决技巧
    在开发过程中,大家难免会下载网络demo用来参考,但是网络上的demo,有很大一部分demo在导入时是报错的,此时就需要修复它让它可以顺畅地运行起来。 在使用demo时,就遇到了一种报......
  • re.findall() 报错:TypeError: expected string or bytes-like object
    复现:解决:importrepattern_str='共(.*?)件商品'result=re.findall(pattern_str,str(b'fsdf'))总结:findall,第二个参数只能是字符串......
  • unity monobehaviour constructor function和SerializationCallbackReceiver对应
    https://answers.unity.com/questions/862032/c-constructor-in-monobehaviour.html See,serializationoftheobjectsinthescene(andthescriptsonthem)happ......
  • unity 骨骼物理 头发 布料模拟
    能够实现模拟布料效果的现在通常使用的有两种:DynamicBoneMagicaCloth(https://magicasoft.jp/magica-cloth/)一般现在使用的布料模拟,会选择这两种,第一种是直接对骨骼节点添加......
  • unity 皮肤材质效果实现分析
    相关资料​​https://therealmjp.github.io/posts/sss-intro/​​​里面讲解了次表明散射的概念原理,以及发展过程。到了实时渲染,早期的基于纹理空间的扩散,到现在经常会应用......
  • unity urp 衣服渲染
    正常衣服的布料分类:棉,羊毛,绒丝绸尼龙皮革还有一些特殊的比如富贵的貂那种绒毛,还有一些闪闪发光的那种。首先说一下基础的棉类的衣服。质地偏软,和之前默认的硬表面有很......
  • unity URP前向渲染流程以及获取屏幕空间UV和深度
    前向渲染流程cpu上进行剔除和排序,剔除为,相机的视椎体剔除,将相机视角外的模型剔除掉,不再渲染。遮挡剔除,将视椎体内不可见的模型剔除掉,不再渲染。排序为了保证性能,不透明为从......