当前位置:网站首页>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 .
边栏推荐
- UWA问答精选
- Redis official ORM framework is more elegant than redistemplate
- Remember an experience of using selectmany
- OpenGL job coordinate system
- [开源] .Net ORM 访问 Firebird 数据库
- PKPM 2020软件安装包下载及安装教程
- Latest Android advanced interview questions summary, Android interview questions and answers
- Oracle advanced (VI) Oracle expdp/impdp details
- Understand the autograd package in pytorch
- Xcode modifies the default background image of launchscreen and still displays the original image
猜你喜欢
Form组件常用校验规则-2(持续更新中~)
operator
The whole network "chases" Zhong Xuegao
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
php 获取图片信息的方法
Matplotlib快速入门
Nx10.0 installation tutorial
PDF文档签名指南
How to realize the movement control of characters in horizontal game
[JDBC Part 1] overview, get connection, CRUD
随机推荐
Form组件常用校验规则-2(持续更新中~)
Aspose. Word operation word document (II)
Record layoutrebuild Forcerebuildlayoutimmediate does not take effect
PHP method of obtaining image information
Antd date component appears in English
IP网络主动测评系统——X-Vision
OpenGL job coordinate system
Implementation method of data platform landing
Pdf document signature Guide
Blender exchange group, welcome to the water group ~
PDF文档签名指南
How to choose the appropriate automated testing tools?
强化学习-学习笔记9 | Multi-Step-TD-Target
Redis官方ORM框架比RedisTemplate更优雅
Understand the autograd package in pytorch
Programming mode - table driven programming
vite Unrestricted file system access to
The essence of analog Servlet
DBSync新增对MongoDB、ES的支持
23. Merge K ascending linked lists -c language