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


边栏推荐
- PDF文档签名指南
- UWA Q & a collection
- 如何选择合适的自动化测试工具?
- npm uninstall和rm直接删除的区别
- Remove the default background color of chrome input input box
- [azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
- OpenGL job coordinate system
- 微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
- Ternary expressions, generative expressions, anonymous functions
- [colmap] sparse reconstruction is converted to mvsnet format input
猜你喜欢

php 获取图片信息的方法

How to choose the appropriate automated testing tools?

vite Unrestricted file system access to

海外代理推荐

How to make agile digital transformation strategy for manufacturing enterprises

Dayu200 experience officer MPPT photovoltaic power generation project dayu200, hi3861, Huawei cloud iotda

Visual design form QT designer design gui single form program

Two kinds of updates lost and Solutions

How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525

Add get disabled for RC form
随机推荐
Firefox browser installation impression notes clipping
如何选择合适的自动化测试工具?
What is the difference between the three values of null Nan undefined in JS
How pyGame rotates pictures
Revit secondary development - collision detection
npm uninstall和rm直接删除的区别
The latest Android interview collection, Android video extraction audio
OpenGL homework - Hello, triangle
UWA Q & a collection
Reinforcement learning - learning notes 9 | multi step TD target
Failed to initialize rosdep after installing ROS
Overseas agent recommendation
Typescript TS basic knowledge type declaration
Px4 autonomous flight
Form组件常用校验规则-2(持续更新中~)
Remember that a development is encountered in the pit of origin string sorting
Typeorm automatically generates entity classes
Build your own website (18)
客户案例|华律网,通过观测云大幅缩短故障定位时间
How to choose the appropriate automated testing tools?