当前位置:网站首页>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 .
边栏推荐
- Preparing for the interview and sharing experience
- Typescript TS basic knowledge type declaration
- Amesim2016 and matlab2017b joint simulation environment construction
- Latest Android advanced interview questions summary, Android interview questions and answers
- MIT6.S081-Lab9 FS [2021Fall]
- 海外代理推荐
- Anti climbing killer
- Gazebo import the mapping model created by blender
- 使用 BlocConsumer 同时构建响应式组件和监听状态
- Record layoutrebuild Forcerebuildlayoutimmediate does not take effect
猜你喜欢
Use json Stringify() to realize deep copy, be careful, there may be a huge hole
How to make agile digital transformation strategy for manufacturing enterprises
operator
How to choose the appropriate automated testing tools?
VTOL in Px4_ att_ Control source code analysis [supplement]
[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
Add get disabled for RC form
Remember an experience of using selectmany
Nx10.0 installation tutorial
Ueeditor custom display insert code
随机推荐
Reinforcement learning - learning notes 9 | multi step TD target
IP network active evaluation system -- x-vision
Use blocconsumer to build responsive components and monitor status at the same time
C development -- WPF simple animation
MIT6.S081-Lab9 FS [2021Fall]
How to choose the appropriate automated testing tools?
IP网络主动测评系统——X-Vision
Use partial derivatives to display normals in unity
[environment] pycharm sets the tool to convert QRC into py file
Customer case | China law network, through observing the cloud, greatly shortens the time of fault location
[advanced MySQL] index details (I): index data page structure
OpenGL homework - Hello, triangle
Visual design form QT designer design gui single form program
What if the win11u disk does not display? Solution to failure of win11 plug-in USB flash disk
Aspose. Word operation word document (II)
强化学习-学习笔记9 | Multi-Step-TD-Target
Form组件常用校验规则-2(持续更新中~)
Px4 autonomous flight
Pdf document signature Guide
Xcode modifies the default background image of launchscreen and still displays the original image