当前位置:网站首页>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 .
边栏推荐
- Vs custom template - take the custom class template as an example
- The latest Android interview collection, Android video extraction audio
- Remember aximp once Use of exe tool
- [problem] pytorch installation
- Robot autonomous exploration series papers environment code
- Details of the open source framework of microservice architecture
- How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525
- Time standard library
- OpenGL jobs - shaders
- Form组件常用校验规则-2(持续更新中~)
猜你喜欢
VTOL in Px4_ att_ Control source code analysis [supplement]
如何实现横版游戏中角色的移动控制
使用 BlocConsumer 同时构建响应式组件和监听状态
IP网络主动测评系统——X-Vision
ByteDance senior engineer interview, easy to get started, fluent
Add get disabled for RC form
PHP method of obtaining image information
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
100million single men and women "online dating", supporting 13billion IPOs
Redis official ORM framework is more elegant than redistemplate
随机推荐
Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
#DAYU200体验官#MPPT光伏发电项目 DAYU200、Hi3861、华为云IotDA
Cannot find module 'xxx' or its corresponding type declaration
Variables and constants
Customer case | China law network, through observing the cloud, greatly shortens the time of fault location
operator
[开源] .Net ORM 访问 Firebird 数据库
JS number is insufficient, and 0 is added
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
Crawler (17) - Interview (2) | crawler interview question bank
The latest Android interview collection, Android video extraction audio
Ueeditor custom display insert code
Add get disabled for RC form
应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
PHP method of obtaining image information
The essence of analog Servlet
Remove the default background color of chrome input input box
Revit secondary development - operation family documents
UWA Q & a collection
Revit secondary development - collision detection