当前位置:网站首页>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 .
边栏推荐
- OpenGL homework - Hello, triangle
- 苹果在iOS 16中通过'虚拟卡'安全功能进一步进军金融领域
- Remember an experience of using selectmany
- Preparing for the interview and sharing experience
- Redis官方ORM框架比RedisTemplate更优雅
- ByteDance senior engineer interview, easy to get started, fluent
- PHP method of obtaining image information
- 海外代理推荐
- How to make agile digital transformation strategy for manufacturing enterprises
- 变量与常量
猜你喜欢
[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
Gazebo import the mapping model created by blender
如何实现横版游戏中角色的移动控制
如何选择合适的自动化测试工具?
苹果在iOS 16中通过'虚拟卡'安全功能进一步进军金融领域
How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
ByteDance Android interview, summary of knowledge points + analysis of interview questions
operator
The whole network "chases" Zhong Xuegao
随机推荐
Tcp/ip protocol stack
What is the difference between the three values of null Nan undefined in JS
[colmap] sparse reconstruction is converted to mvsnet format input
Form组件常用校验规则-2(持续更新中~)
Two methods of calling WCF service by C #
Which futures company is the safest to open a futures account?
OpenGL configure assimp
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)
Aspose. Word operation word document (II)
Amesim2016 and matlab2017b joint simulation environment construction
Welcome to CSDN markdown editor
SAR影像质量评估
Typeorm automatically generates entity classes
Nx10.0 installation tutorial
Tsconfig of typescript TS basics JSON configuration options
Preparing for the interview and sharing experience
Gazebo import the mapping model created by blender
Vs custom template - take the custom class template as an example
Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
Add get disabled for RC form