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

Initial support for prefab preview thumbnails #1931

Closed
wants to merge 1 commit into from

Conversation

vhristov
Copy link
Contributor

@vhristov vhristov commented Jul 27, 2021

This is an early (WIP) request for comment on preliminary (and very limited) support for prefab thumbnails ( #1722 ).

Currently the prefab assets don't include any visual hint that there are any spine skeletons in them.
The reason for this is basically that when saving a asset results in MeshFilter's sharedMesh being invalid. This can be caused by one of the following reasons (depending on the current state of the SkeleonRenderer object):

  • Mesh being a scene only object (it cannot be used in for asset preview) and
  • Mesh being destroyed after prefab is saved (by disposing the double buffered meshes)
  • Mesh is null

The fact that the dynamic mesh is scene only object results in type mismatch mesh (partially handled by #1387 ) which then results in null mesh on the subsequent prefab modifications.

This change introduces an extra asset next to SkeletonData asset, that holds the a mesh in SetupPose which is attached to the sharedMesh when prefab is being saved. This way a thumbnail is generated with the default setup pose for every spine skeleton inside a prefab.

This pull request is more of an initial proof-of-concept and a scream for help

Known things that needs to be completed (and verified):

  • Skins support - currently only default skin's mesh is generated (could work in some cases)
  • Dynamic mesh save support when editing prefab and attaching it instead of the setup pose mesh
  • Fix player build with mesh.hideFlags = HideFlags.DontSaveInBuild
  • Split mesh and multiple atlas support (what is this actually?)
  • Skeleton Graphics support (is it even possible to have prefab preview for canvas?)
  • Check unity compatibility (and possibly hide everything behind a define)
  • Reimport prefab inconsistent warning
  • What other stuff needs to be supported to prevent random editor failures

While I haven't check a lot of possible scenarios, the simple change presented here seems to work in the most simple use-case. I don't know if it could create any fatal error, but I guess it can have a corner case where an error is logged to the console while saving a prefab. At least on the spine examples I imported nothing broke during the import.

What I mostly want to do as a next step is to enable dynamic mesh save support (I believe this will also fix skin support?)
I imagine this to happen by adding the mesh to the prefab asset (using AssetDatabase.AddObjectToAsset(mesh, prefab) and updating it when changed. I tried to do that by scraping out the double buffer and pointing the mesh to an asset.
What I failed to achieve here is two thing:

  • to detect when actually a spine skeleton is edited inside a prefab. I believe Experimental.SceneManagement.PrefabStage.IsPartOfPrefabContents() is a good start, but unfortunately It fails to run while called in Awake or OnEnable and I am uncertain how can to handle the mesh substitution after that.
  • to detect prefab creating and substitute the buffer with proper data

Another issue with the above approach I see is how to handle the embedded mesh assets inside the prefab. I haven't come up yet with an idea how to clean up the garbage (for example when a skeleton is deleted from a prefab), how to resolve name collisions (with multiple skeletons inside a prefab), nor how to handle nested prefabs.

Any suggestions on how to proceed further with this are welcome (also any comment on the above checks too)

In order to support prefab thumbnails MeshFilter.sharedMesh needs to be
saved as an asset, otherwise the scene mesh will be used by unity, which
creates a type mismatch. To overcome this problem a prefab asset post
processor is introduced to generate and save a new mesh with the prefab.

When a prefab is created/updated this post process script is run and
generates a new skeleton mesh and saves the one stored in MeshFilter
component for each game object with SkeletonRenderer component attached.
This way unity can use this saved in prefab mesh to generate preview
thumbnail for the prefab.
@vhristov
Copy link
Contributor Author

After posting the previous message I realized it is possible to reuse the same logic in the asset postprocessor, but instead of attaching a pre-generated asset file, it can be used to generate and store in the prefab a new one. As far as I can tell it solved a few of the issues mentioned above - it supports dynamic mesh and skins.

@vhristov
Copy link
Contributor Author

As it turned out this pull request breaks player build. For this reason I am closing this pull-request for the moment to prevent anyone cherry-picking it and realizing their builds are broken by it on a later state.

@vhristov vhristov closed this Jul 29, 2021
HaraldCsaszar added a commit that referenced this pull request Aug 4, 2021
…b instance always listing MeshFilter as changed (via parameter `Advanced - Fix Prefab Override MeshFilter`, see changelog). Closes #1273.
vhristov added a commit to vhristov/spine-runtimes that referenced this pull request Aug 6, 2021
With the new prefab processing there is an issue where the mesh tries to
get into the build. To prevent this a build pre/post process is
introduced that will clean up the prefab from the meshes before the
build and restore the prefab meshes after the build.

This change reverts bf70a62 and is related to EsotericSoftware#1273,EsotericSoftware#1931.
vhristov added a commit to vhristov/spine-runtimes that referenced this pull request Aug 6, 2021
With the new prefab processing there is an issue where the mesh tries to
get into the build. To prevent this a build pre/post process is
introduced that will clean up the prefab from the meshes before the
build and restore the prefab meshes after the build.

This change reverts bf70a62 and is related to EsotericSoftware#1273,EsotericSoftware#1931.
vhristov added a commit to vhristov/spine-runtimes that referenced this pull request Aug 6, 2021
With the new prefab processing there is an issue where the mesh tries to
get into the build. To prevent this a build pre/post process is
introduced that will clean up the prefab from the meshes before the
build and restore the prefab meshes after the build.

This change reverts bf70a62 and is related to EsotericSoftware#1273,EsotericSoftware#1931.
HaraldCsaszar added a commit that referenced this pull request Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant