当前位置:网站首页>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 .
边栏推荐
- php 记录完整对接腾讯云直播以及im直播群聊 所遇到的坑
- Which futures company is the safest to open a futures account?
- 新版代挂网站PHP源码+去除授权/支持燃鹅代抽
- Two kinds of updates lost and Solutions
- Use json Stringify() to realize deep copy, be careful, there may be a huge hole
- OpenGL job - texture
- Cannot find module 'xxx' or its corresponding type declaration
- Px4 autonomous flight
- OpenGL configuration vs2019
- Attitude estimation (complementary filtering)
猜你喜欢
UWA问答精选
How pyGame rotates pictures
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xf9 in position 56: illegal multibyte sequence
Blender exchange group, welcome to the water group ~
Add get disabled for RC form
How to choose the appropriate automated testing tools?
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
Use blocconsumer to build responsive components and monitor status at the same time
Tcp/ip protocol stack
Remember aximp once Use of exe tool
随机推荐
SAR影像质量评估
Revit secondary development - wall opening
Get the week start time and week end time of the current date
[colmap] sparse reconstruction is converted to mvsnet format input
Unity development --- the mouse controls the camera to move, rotate and zoom
The PHP source code of the new website + remove authorization / support burning goose instead of pumping
Revit secondary development - cut view
How pyGame rotates pictures
What if the win11u disk does not display? Solution to failure of win11 plug-in USB flash disk
Form组件常用校验规则-2(持续更新中~)
How to write an augmented matrix into TXT file
Install mxnet GPU version
null == undefined
Typeorm automatically generates entity classes
Redis official ORM framework is more elegant than redistemplate
VTOL in Px4_ att_ Control source code analysis [supplement]
Revit secondary development - collision detection
C development - interprocess communication - named pipeline
OpenGL configure assimp
Paint basic graphics with custompaint