unity场景初始化_Unity对象初始化同步

本文讨论了Unity中MonoBehaviour函数的执行顺序,尤其是Start和Update的调用时机。当不同脚本间的初始化顺序产生依赖时,可能出现错误。通过调整脚本执行顺序设置,确保相关对象初始化完成后再执行Update,可以解决此类同步问题。
摘要由CSDN通过智能技术生成

Until now, I've been coding thinking that functions in monobehaviour would be executed in this order:

OnEnable > Start > Update > OnDisable

The problem is that I thought that this order would be absolute, meaning that until a function is not completely finished, there's no way that the next one would start being executed.

So first question is: Is that true? Would update NOT be executed until start ends?

Then my problem arises with synchronization between different monobehaviour classes.

I have a class that creates some objects (a Menu basically) in its start function. Then in a different class, I've a similar code, but it also depends on the object created by the first class to exist already. I'm getting an error because the object is not found yet.

NullReferenceException: Object reference not set to an instance of an object Sho

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值