控制是否允许在编辑器中使用跨场景引用。
在编辑器中加载多个场景时,会出现跨场景引用,附加到一个场景中某个游戏对象的组件会引用另一个场景中的某个游戏对象。
此设置的默认值是“true”。这意味着,默认情况下,无法在 Unity 编辑器中创建跨场景引用。
默认情况下,禁止创建跨场景引用,因为跨场景引用在场景文件中无法保存。因此,编辑器将禁止您创建这些引用,以免出现您的分配无法保存等这种潜在情况。如果您在运行时需要跨场景引用,则需要在运行时创建这些引用,方法是按名称或标记等值来查找游戏对象。
但是,在某些情况下,您可能需要在编辑器中创建跨场景引用(即使这些引用无法保存),例如,如果您需要创建应能够一次针对多个场景在游戏对象上运行的编辑器脚本。停用此设置,即可执行此操作。
但请注意,停用此值并不是意味着将能够保存跨场景引用。
禁用此设置意味着:
1) 允许将来自一个场景中游戏对象的引用拖放到其他场景中另一个游戏对象的组件字段。
2) Object Picker(Inspector 中最可能分配字段旁边小的目标图标)会列出所有打开的场景中的选项,而非只是游戏对象自身的场景。
3) 将一个场景中的游戏对象拖放到另一个场景中,可生成跨场景引用。
如果生成了跨场景引用,则不再记录警告。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.