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


边栏推荐
- Details of the open source framework of microservice architecture
- Time standard library
- 客户案例|华律网,通过观测云大幅缩短故障定位时间
- Remember an experience of using selectmany
- How to choose the appropriate automated testing tools?
- Remove the default background color of chrome input input box
- Aspose. Word operation word document (II)
- Firefox browser installation impression notes clipping
- Revit secondary development - intercept project error / warning pop-up
- Record problems fgui tween animation will be inexplicably killed
猜你喜欢

海外代理推荐

Ueeditor custom display insert code

Overseas agent recommendation

新版代挂网站PHP源码+去除授权/支持燃鹅代抽

Two kinds of updates lost and Solutions

【Azure微服务 Service Fabric 】在SF节点中开启Performance Monitor及设置抓取进程的方式
Redis官方ORM框架比RedisTemplate更优雅

Add get disabled for RC form

The strongest installation of the twin tower model, Google is playing "antique" again?
![[JDBC Part 1] overview, get connection, CRUD](/img/53/d79f29f102c81c9b0b7b439c78603b.png)
[JDBC Part 1] overview, get connection, CRUD
随机推荐
Reinforcement learning - learning notes 9 | multi step TD target
PDF文档签名指南
PKPM 2020 software installation package download and installation tutorial
How to judge whether the input content is "number"
Attitude estimation (complementary filtering)
Aspose. Words merge cells
[azure microservice service fabric] how to transfer seed nodes in the service fabric cluster
Ueeditor custom display insert code
Ternary expressions, generative expressions, anonymous functions
Get the week start time and week end time of the current date
The essence of analog Servlet
UWA Q & a collection
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xf9 in position 56: illegal multibyte sequence
null == undefined
Revit secondary development - shielding warning prompt window
UWA问答精选
vite Unrestricted file system access to
How to close eslint related rules
Preparing for the interview and sharing experience
Oracle advanced (VI) Oracle expdp/impdp details