Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mesh preview causes empty mesh if reload scene on enter play mode is disabled #1064

Merged
merged 2 commits into from
May 10, 2024

Conversation

nekobako
Copy link
Contributor

@nekobako nekobako commented May 9, 2024

Fixes #1049 です。

MeshInfo2.WriteToSkinnedMeshRenderer() で正しく AAOGeneratedMeshXXXX が割り当てられた後、
MeshPreviewController.Update() から StopPreview() が呼ばれて元アセットのメッシュに戻っているようでした。

本 pullreq ではここで StopPreview() を呼ぶようにしていますが、そうしないようコメントにあるのは Play ボタンを押してから Reload Domain/Scene 中にメッシュが完全に消えて見えることへの対策でしょうか?

case PlayModeStateChange.ExitingEditMode:
// stop previewing when exit edit mode
Debug.Log("stop previewing when exit edit mode");
// Exiting Animation mode on entering play mode may leave the mesh none so we just rollback mesh to original one
if (AnimationMode.InAnimationMode(DriverCached) && _previewController != null)
{
try
{
AnimationMode.BeginSampling();
AnimationMode.AddPropertyModification(
EditorCurveBinding.PPtrCurve("", typeof(SkinnedMeshRenderer), "m_Mesh"),
new PropertyModification
{
target = _previewController.TargetRenderer,
propertyPath = "m_Mesh",
objectReference = _previewController.OriginalMesh,
},
true);
_previewController.TargetRenderer.sharedMesh = _previewController.OriginalMesh;
}
finally
{
AnimationMode.EndSampling();
}
}

もしそうでしたら、ここで StopPreview() を呼ぶだけだと直後の Update() で再び StartPrevew() されてしまうことが原因なので、EditorApplication.isPlaying の判定を EditorApplication.isPlayingOrWillChangePlaymode に変更している本 pullreq の対応であれば大丈夫かなと思います。(Reload Domain/Scene がオンの場合 Reload Domain/Scene 中はプレビューが終了した状態が見えます)

そうではない別の事象への対策ということであれば、大丈夫ではないかもしれません。

@nekobako nekobako marked this pull request as ready for review May 9, 2024 14:16
Copy link
Owner

@anatawa12 anatawa12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。

そうしないようコメントにあるのは Play ボタンを押してから Reload Domain/Scene 中にメッシュが完全に消えて見えることへの対策でしょうか?

そのとおりです。イベントの順番とフラグを間違っていたのか

@anatawa12 anatawa12 merged commit 3c3fff8 into anatawa12:master May 10, 2024
8 checks passed
@nekobako nekobako deleted the mesh-preview-empty-mesh branch May 10, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants