Unity编辑器 - Undo的坑

Unity编辑器在脚本中更改值时,使用Undo.RecordObject可能无法正确撤销操作。应改用Undo.RegisterCompleteObjectUndo或Undo.RegisterFullObjectHierarchyUndo。这两个方法分别记录对象的完整状态和对象及其所有子对象和组件的状态,确保在复杂情况下能正确计算差异。错误消息'Generating diff of this object for undo...'提示应使用Undo.RegisterCompleteObjectUndo来处理脚本属性变更。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Unity编辑器 - Undo的坑

编辑器通过脚本中改变值,Undo.RecordObject可能会无效,应该使用:
Undo.RegisterCompleteObjectUndo(Object objectToUndo, string name)
该方法会记录对象的完整状态的拷贝。

The Unity documentation has been updated since:

https://docs.unity3d.com/ScriptReference/Undo.RegisterCompleteObjectUndo.html
https://docs.unity3d.com/ScriptReference/Undo.RegisterFullObjectHierarchyUndo.html

Undo.RegisterCompleteObjectUndo(Object objectToUndo, string name) will
record a copy of the full state of the object that it will keep,
unlike Undo.RecordObject(Object objectToUndo, string name) that will
only keep a copy of the state until the end of the frame to compute a
diff.

By the way, I ju

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值