当前位置:网站首页>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 .


边栏推荐
- 如何实现横版游戏中角色的移动控制
- Revit secondary development - Hide occlusion elements
- How to choose the appropriate automated testing tools?
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
- Dayu200 experience officer MPPT photovoltaic power generation project dayu200, hi3861, Huawei cloud iotda
- The essence of analog Servlet
- [azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)
- Vs custom template - take the custom class template as an example
- Leetcode SQL first day
- The free styling service of Dyson's official direct store is now open for appointment. Pioneer Technology interprets the styling concept of hair care and helps consumers unlock diversified and shiny s
猜你喜欢

Matplotlib quick start

The PHP source code of the new website + remove authorization / support burning goose instead of pumping

Two kinds of updates lost and Solutions

DNS series (I): why does the updated DNS record not take effect?

Add get disabled for RC form
![[problem] pytorch installation](/img/9f/1419c471838e3af8ea2158266254a5.jpg)
[problem] pytorch installation

Record a garbled code during servlet learning
![[JDBC Part 1] overview, get connection, CRUD](/img/53/d79f29f102c81c9b0b7b439c78603b.png)
[JDBC Part 1] overview, get connection, CRUD

How to choose the appropriate automated testing tools?
Preparing for the interview and sharing experience
随机推荐
IP网络主动测评系统——X-Vision
SAR image quality evaluation
Dayu200 experience officer MPPT photovoltaic power generation project dayu200, hi3861, Huawei cloud iotda
Revit secondary development - project file to family file
OpenGL jobs - shaders
Latest Android advanced interview questions summary, Android interview questions and answers
使用 BlocConsumer 同时构建响应式组件和监听状态
Redis官方ORM框架比RedisTemplate更优雅
UWA问答精选
How to judge whether the input content is "number"
双塔模型的最强出装,谷歌又开始玩起“老古董”了?
Write in front -- Talking about program development
Customer case | China law network, through observing the cloud, greatly shortens the time of fault location
ByteDance Android interview, summary of knowledge points + analysis of interview questions
Revit secondary development - wall opening
使用 CustomPaint 绘制基本图形
Cannot find module 'xxx' or its corresponding type declaration
[open source] Net ORM accessing Firebird database
Pdf document signature Guide
如何选择合适的自动化测试工具?