当前位置:网站首页>Unity FAQ (I) lack of references
Unity FAQ (I) lack of references
2022-07-07 22:31:00 【Dimensional survivor】
Problem description
When an object is called Unity An error message appears indicating that the reference is empty .
This is Unity The most common problem in English , Usually, the error message is
NullReferenceException: Object reference not set to an instance of an object
perhaps
UnassignedReferenceException
Question why
Usually, it is because the script defines some requirements in unity Manually drag and drop the mounted object in the , But it is not mounted . Or you want to get a component of an object, but the object does not carry the component . It is also possible that an object is destroyed during the run , But the object is still being called .
resolvent
Find the missing reference object , Mount correctly .
Sample questions
For example, here we want the character controller (PlayerController) Generate a bullet (Bullet), But forget to hang the bullet preform to the script we need .
public class PlayerController : MonoBehaviour
{
public GameObject bullet;
void Start()
{
Instantiate(bullet);
}
}
The content of the error report is as follows

Problem example 2
The correct mount has been performed here , We want to call the... On the bullet object Bullet Within the script component Fly function .

public class PlayerController : MonoBehaviour
{
public GameObject bullet;
void Start()
{
bullet.GetComponent<Bullet>().Fly();
}
}However, the bullet object does not have the corresponding script component attached , This causes the acquisition to fail .


边栏推荐
- How to judge whether the input content is "number"
- Aspose. Words merge cells
- Add get disabled for RC form
- OpenGL configuration vs2019
- php 获取图片信息的方法
- UWA问答精选
- Blender exchange group, welcome to the water group ~
- [advanced MySQL] index details (I): index data page structure
- Pyqt GUI interface and logic separation
- UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xf9 in position 56: illegal multibyte sequence
猜你喜欢

应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设

The whole network "chases" Zhong Xuegao

How to choose the appropriate automated testing tools?

The strongest installation of the twin tower model, Google is playing "antique" again?

UWA Q & a collection

. Net automapper use

微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹

Customer case | China law network, through observing the cloud, greatly shortens the time of fault location

C # realizes the communication between Modbus protocol and PLC

Firefox browser installation impression notes clipping
随机推荐
Revit secondary development - get the project file path
Tsconfig of typescript TS basics JSON configuration options
Revit secondary development - modify wall thickness
ByteDance Android interview, summary of knowledge points + analysis of interview questions
Cannot find module 'xxx' or its corresponding type declaration
【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)
Node:504 error reporting
Visual design form QT designer design gui single form program
PHP method of obtaining image information
The function is really powerful!
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
IP网络主动测评系统——X-Vision
23. Merge K ascending linked lists -c language
【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
Blender exchange group, welcome to the water group ~
OpenGL configuration vs2019
OpenGL configure assimp
How to judge whether the input content is "number"
C development - interprocess communication - named pipeline