当前位置:网站首页>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 .
边栏推荐
- 【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
- Kaggle-Titanic
- Aspose. Words merge cells
- The strongest installation of the twin tower model, Google is playing "antique" again?
- Cannot find module 'xxx' or its corresponding type declaration
- 如何选择合适的自动化测试工具?
- OpeGL personal notes - lights
- Antd date component appears in English
- 怎样写一个增广矩阵到txt文件中
- PHP records the pitfalls encountered in the complete docking of Tencent cloud live broadcast and im live group chat
猜你喜欢
OpenGL configuration vs2019
Robot autonomous exploration series papers environment code
[advanced MySQL] index details (I): index data page structure
Record a garbled code during servlet learning
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xf9 in position 56: illegal multibyte sequence
Ternary expressions, generative expressions, anonymous functions
反爬通杀神器
Robot autonomous exploration DSVP: code parsing
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
. Net automapper use
随机推荐
Anti climbing killer
[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
Tcp/ip protocol stack
Visual design form QT designer design gui single form program
How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525
Kaggle-Titanic
[open source] Net ORM accessing Firebird database
Pyqt GUI interface and logic separation
C # Development -- pit encountered in JS intermodulation
Aspose. Words merge cells
Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
Cataloger integrates lidar and IMU for 2D mapping
How to realize the movement control of characters in horizontal game
Welcome to CSDN markdown editor
Redis official ORM framework is more elegant than redistemplate
Px4 autonomous flight
Vs custom template - take the custom class template as an example
Revit secondary development - Hide occlusion elements
Matplotlib快速入门
Reinforcement learning - learning notes 9 | multi step TD target