- Edited
[Unity] Nested prefab overrides
Unity 2018.3
Spine Runtime 3.7.xx
I don't have any changes in my prefab,
but Mesh Filter components show 'overrides' always.
I know why Mesh Filter has overrides(dynamic mesh)...
Can I ignore (or hide) this overrides?
프리팹 상에서 아무런 변화도 없지만
Mesh Filter 컴퍼넌트가 overrides를 보여줍니다.
왜 Mesh Filter가 overrides를 가지는지는 알고있습니다만(dynamic mesh)...
이 override를 무시할 수 있는 방법이 있을까요?
Thanks for reporting this problem.
Unfortunately, I could not find a quick solution yet.
I have created a bug ticket here for you to subscribe:
https://github.com/EsotericSoftware/spine-runtimes/issues/1273
I will let you know once it is resolved.
이 문제를 신고 해 주셔서 감사합니다.
불행히도 아직 빠른 해결책을 찾지 못했습니다.
구독 할 수 있도록 여기에 버그 티켓을 만들었습니다.
https://github.com/EsotericSoftware/spine-runtimes/issues/1273
일단 해결되면 알려 드리겠습니다.
다음 발행 티켓이 방금 구현되었습니다.
-
SkeletonRenderer
,SkeletonAnimation
및SkeletonMecanim
이 포함된 프리팹은 이제 미리보기 축소판을 포함하여 적절한 편집기 미리보기를 제공합니다. -
SkeletonRenderer
(및 하위 클래스SkeletonAnimation
및SkeletonMecanim
)는 이제Advanced - Fix Prefab Override MeshFilter
속성을 제공합니다. 이 속성은 활성화되면 항상 변경된 것으로 표시되는 프리팹을 수정합니다. MeshFilter의 숨기기 플래그를 'DontSaveInEditor'로 설정합니다. 불행히도 이것은 다른 구성 요소에 의해 'MeshFilter'에 대한 참조가 손실되므로 이 매개변수는 기본적으로 'false'로 설정되어 안전한 기존 동작을 유지합니다.
조립식 재정의 버그는 활성화해야 하는 bool 매개변수를 통해 해결되었습니다. 그렇지 않으면 MeshFilter
에 대한 기존 참조가 손실됩니다. 다행히 미리보기는 매개변수의 활성화 여부에 관계없이 적절한 썸네일을 보여주므로 OnPostProcessPrefab
을 사용하라는 힌트가 실제로 매우 도움이 되는 것으로 나타났습니다. RequireComponent(typeof(MeshFilter))
부분은 SkeletonRenderer
에서 제거되고 수동으로 MeshFilter를 생성하여 대체되어 일부 성가신 경고를 피할 수 있습니다.
새로운 4.0 unitypackage는 평소와 같이 여기에서 다운로드할 수 있습니다.
Spine Unity Download
보고해 주셔서 다시 한 번 감사드립니다. 사용 사례에도 적용되기를 바랍니다! 문제가 발생하면 알려주십시오.
These issue tickets have just been implemented:
-
Prefabs containing
SkeletonRenderer
,SkeletonAnimation
andSkeletonMecanim
now provide a proper Editor preview, including the preview thumbnail. -
SkeletonRenderer
(and subclassesSkeletonAnimation
andSkeletonMecanim
) now provide a propertyAdvanced - Fix Prefab Override MeshFilter
, which when enabled fixes the prefab always being marked as changed. It sets the MeshFilter's hide flags toDontSaveInEditor
. Unfortunately this comes at the cost of references to theMeshFilter
by other components being lost, therefore this parameter defaults tofalse
to keep the safe existing behaviour.
The prefab override bug was resolved via a bool parameter which has to be enabled, as otherwise existing references to the MeshFilter
would be lost. Fortunately the preview shows a proper thumbnail regardless of the parameter being enabled or disabled, so your hint of using OnPostProcessPrefab
turned out to be very helpful indeed. The RequireComponent(typeof(MeshFilter))
part has been removed from SkeletonRenderer
and replaced by generating the MeshFilter manually, which avoids some annoying warnings.
A new 4.0 unitypackage is available for download here as usual:
Spine Unity Download
Thanks again for reporting, hope it works for your use cases too! Please let us know if you encounter any problems.
Finally!!
Thank you for your effort!
I am glad that this issue has been resolved.
Thanks for your kind words. Sorry it took so long, unfortunately it was causing a lot of troubles to get it working.
We have released another bugfix a few minutes ago regarding prefab references causing build errors after the last commit:
Spine Unity Download: Download
So if you downloaded the unitypackage already, please be sure to download it again with the latest update.
Thank you Harald!
This feature works good in scene.
But I found an issue with nested prefab.
So I added some code to 'SkeletonRenderer.EditorUpdateMeshFilterHideFlags'.
public void EditorUpdateMeshFilterHideFlags () {
if (!meshFilter) {
meshFilter = GetComponent<MeshFilter>();
if (meshFilter == null)
meshFilter = gameObject.AddComponent<MeshFilter>();
}
if (fixPrefabOverrideViaMeshFilter) {
//For nested prefab - start
#if UNITY_EDITOR && NEW_PREFAB_SYSTEM
if (UnityEditor.PrefabUtility.IsPartOfAnyPrefab(meshFilter)) {
UnityEditor.PrefabUtility.RevertObjectOverride(meshFilter, UnityEditor.InteractionMode.AutomatedAction);
}
//For nested prefab - end
#endif
meshFilter.hideFlags = HideFlags.DontSaveInEditor;
}
else {
meshFilter.hideFlags = HideFlags.None;
}
}
It works fine for me.
However, not all cases have been thoroughly tested.
Here is a video about this.
Unity 2020.2.6f1
Spine Unity Runtime 4.0-2021-08-06
Unfortunately my code dosen't work sometimes with nested prefab perfectly.
I'm trying the other way.
Thanks for reporting! It's a pity this is causing problems now, thanks very much for your efforts. Unfortunately your modifications did not fix the issue on our end, but we are very much looking forward to your other way of solving this issue. We are working on this issue as well, unfortunately without a working solution so far.
I found a new solution!
I have raised a PR. Could you please review this PR.
https://github.com/EsotericSoftware/spine-runtimes/pull/1939
'ObjectOverride.Revert(or PrefabUtility.RevertObjectOverride)' is the cause of OnDisable, OnEnable being called.
So ObjectOverride.Revert will called only once and other prefab's LateUpdate will ignored.
To prevent this, I added LateUpdate in OnEnable.
Here is a example what happend without LateUpdate in OnEnable.
Each time the button is pressed, LateUpdate is called.
But prefabs are reverted one by one.
You are the best! 8) Your solution works very well, thanks a lot!
We would like to merge your pull request. For legal reasons, could you please send us the following contribution license agreement signed to contact@esotericsoftware.com:
https://github.com/EsotericSoftware/spine-runtimes#contributing
You only need to sign this once for any future pull requests, if you've already signed such an agreement, please let me know.
Thanks again!
Thank you!
I have just sent an email now.
I have realized that this solution works without external mesh.
// SpineEditorUtilities.cs
public static bool SetupSpinePrefabMesh(GameObject g, UnityEditor.AssetImporters.AssetImportContext context)
{
bool wasModified = false;
var skeletonRenderers = g.GetComponentsInChildren<SkeletonRenderer>(true);
foreach (SkeletonRenderer renderer in skeletonRenderers) {
wasModified = true;
var meshFilter = renderer.GetComponent<MeshFilter>();
if (meshFilter == null)
meshFilter = renderer.gameObject.AddComponent<MeshFilter>();
renderer.EditorUpdateMeshFilterHideFlags();
renderer.Initialize(true, true);
renderer.LateUpdateMesh();
var mesh = meshFilter.sharedMesh;
if (mesh == null) continue;
string meshName = string.Format("Skeleton Prefab Mesh \"{0}\"", renderer.name);
mesh.name = meshName;
mesh.hideFlags = HideFlags.None;
// without this ↓
//if (context != null)
// context.AddObjectToAsset(meshFilter.sharedMesh.name, meshFilter.sharedMesh);
}
return wasModified;
}
Sekomu wroteThank you!
I have just sent an email now.
Thanks very much for sending the CLA, we received everything and I've merged the pull request. A new 4.0 spine-unity package is available for download here as usual:
Spine Unity Download
I have added two commits, one just adds a #if UNITY_EDITOR
guard around OnEnable
to improve things slightly. A second commit was pushed which replaces ObjectOverride.Revert(InteractionMode)
with ObjectOverride.Revert()
without any parameter, since this led to compile errors on earlier Unity versions. Strangely the variant with the InteractionMode
parameter is not even documented on Unity's docs pages. After removing the passed parameter UnityEditor.InteractionMode.AutomatedAction
from the Revert
call everything still worked as expected, so it may be a safe replacement.
Did you use Revert(InteractionMode.AutomatedAction)
on purpose, or was this just e.g. the first method that auto-complete offered? If it has any advantages, we could still add some #if
branches to use it on more recent Unity versions.
Thanks again for your great contribution! :cooldoge:
Thanks for your commit, merge!
Harald wroteDid you use Revert(InteractionMode.AutomatedAction) on purpose, or was this just e.g. the first method that auto-complete offered? If it has any advantages, we could still add some #if branches to use it on more recent Unity versions.
I think it has no advantage of 'Revert(InteractionMode.AutomatedAction)'.
Sekomu wroteI think it has no advantage of 'Revert(InteractionMode.AutomatedAction)'.
Thanks very much for confirming.