Jump to content
Sign in to follow this  
superstar

The prefab's mesh reference disappears after applying changes

Recommended Posts

Hi,

 

Polybrush 0.9.6b0

 

After painting onto a prefab instance (only Non-Probuilder prefabs) and then applying changes to the prefab, for some reason, the mesh reference disappears from the prefab in the Project.  The prefab instance (the instance that was painted on) that lives in the Hierarchy still shows a modified mesh reference, but the root prefab, the one sitting in the Project tab had automatically updated to have no mesh.

 

This may sound confusing to explain, but I will try and list the following below to clarify:

 

Before applying changes to the prefab (Polybrush painted)

Prefab Instance (Hierarchy Tab)

    Mesh:   z0_Mesh

 

Prefab  (Project Folder)

    Mesh:   Mesh

 

After applying changes to the prefab (Polybrush painted)

Prefab Instance (Hierarchy Tab)

    Mesh:   z0_Mesh

 

Prefab  (Project Folder)

    Mesh:   None (Mesh)

 

 

The mesh values shown above are the values displayed when viewed with the Inspector.

 

So far, this seems to only happen on Non-ProBuilder prefabs.

 

Can you verify that this is occurring?

 

 

Thanks

Share this post


Link to post
Share on other sites

Yes, that's because the painted mesh is a new instanced one in that scene.  This is how Polybrush allows you to paint multiple prefabs with different colors.

 

The fix is to use the "Save to Asset" button in the MeshFilter component before applying prefab changes.  This creates a new mesh asset that the prefab can reference.

 

See also: http://procore3d.github.io/polybrush/troubleshooting/#save-mesh-as-asset

Share this post


Link to post
Share on other sites

Hi, I'm just trying out Polybrush this morning, and came across a similar problem as the original poster.  When I paint textures on an object in the scene, then drag to my prefabs folder, I lose the data that I've painted onto the object (the 'Z_Additional Vertex Streams' field changes to 'None (mesh)') so cannot reuse it as a prefab with the same texture painting applied on new instances.

The fix described above seems to be exactly what I need, unfortunately I cannot for the life of me find the "Save to Asset" button in the MeshFilter component mentioned in the documentation, and described above as the fix.

I am quite new to Unity, so maybe I'm just looking in the wrong place, or misunderstanding something.  Would it be possible to describe a bit more precisely where I should be looking for the "Save to Asset" button?  I'm selecting my object in the Scene view, looking in Inspector at the Mesh Filter section, and all I see is the mesh name, Instance ID and Local Identifier In File values.

Thanks.


Edit:
With a bit more testing, if I create a new model in the scene, then add a Polybrush/Standard_Texture_Blend material I've created to the model, I see the "Save to Asset" button in the Mesh Filter component in the Inspector (so I'm looking in the right place).

If I import a mesh I've created in Blender, add that to the scene, then add the Polybrush/Standard_Texture_Blend material to it, I don't get any "Save to Asset" button in the Mesh Filter component, so I'm unable to make a prefab with blended textures that I can then reuse in the scene. 

Edited by Ste Pickford
More testing

Share this post


Link to post
Share on other sites

The "Save to Asset" button only appears when the mesh in one that has been modified by Polybrush and lives in the scene view. If it's not there, that means the mesh is already persistent in your project.

Similarly, if you're painting using additional vertex streams this option is not available because the MeshFilter mesh is not modified. So if you want to use a painted mesh as a prefab, paint it with "Additional Vertex Streams" set to "Off" and then use the "Save to Asset" button.

Share this post


Link to post
Share on other sites

Hi Karl, thanks for the response.

I'm not quite sure what you mean by set to 'Off'.  Do you mean unchecking the tickbox next to Z_Additional Vertex Streams in the Inspector?  If I do that the texture painting on the model seems to disappear sometimes when it's unselected in the scene, and no Save to Asset button appears.  Deleting the component removes the textures I've painted on the model, until I try to repaint it again, at which point it's added again.  I still never see the Save to Asset button in the Mesh Filter component on my imported models.

Share this post


Link to post
Share on other sites

Do you mean unchecking the tickbox next to Z_Additional Vertex Streams in the Inspector?

Yes, exactly.

> I still never see the Save to Asset button in the Mesh Filter component on my imported models.

Are there any other plugins in your project that could be modifying the Inspector? If not it sounds like you may be encountering a bug.

Share this post


Link to post
Share on other sites

Thanks again for the response Karl.

We don't have any other plugins installed.  The version of Unity we're using is 2017.3.1f1.  The version of Polybrush we have installed is 0.9.13b0.

I've done a bit more testing to try to narrow down the problem.

I created a 10x10x10 cube in blender with UV coordinates, and exported this as an .fbx file. I then selected Import New Asset... and imported this file into my Project folder, then dragged it into a brand new scene. I applied a Polybrush/Standard Texture Blend material I had already created, and used the Polybrush Window 'Paint Textures' tab to paint different textures on different corners of the cube.  As before, no Save to Asset button appears in the Mesh Filter component in the Inspector.  Dragging this painted model in my prefabs folder loses the painted textures, so I'm unable to reuse the textures I've painted as a prefab.

I did discover that I can duplicate this instance of the cube model that I've painted in the scene by right clicking the cube in the scene Hierarchy view, and selecting Duplicate.  This creates another instance of the cube in the scene, with the same painted textures, and I can make any number of duplicates.  This *seems* to do what I need, although it's a bit flaky.  I cannot reuse a model painted this way in another scene.  Also, it seems very easy to accidentally lose the texture data I painted.  For example, at one point I selected a different object in the scene, opened the Polybrush window, and started painting textures on this different object.  My cursor briefly hovered over my original object that I had already painted in the scene and 'poof' - all my painted textures disappeared from the unselected object.  The data in the Z_Additional Vertex Streams field on this unselected object was gone ("None (mesh)"). I presume this is a bug?  I doesn't happen all the time, so I can't reliably explain the conditions to duplicate this issue, but it happened two or three times when I was messing around in a scene, so it's fairly common.

I then tried a test without an imported model.  I created a 10x10x10 cube in the scene, applied the same Polybrush/Standard Texture Blend material I had already created, and used the Polybrush Window 'Paint Textures' tab to paint different textures on different corners of this cube.  This time the Save to Asset button does appear.  I clicked this button, got a 'Save Mesh As' dialogue box, with 'Cube.asset' as the filename given, and pressed the Save button.  However, now I get two Unity Console errors:

Couldn't add object to asset file because the Mesh 'Cube' is already an asset at 'Library/unity default resources'!

UnityException: Creating asset at path Assets/Cube.asset failed.

I tried changing the filename to something unique, and tried saving in different subfolders in my assets folders, but I got the same errors each time.  I don't know if this last issue is me doing something wrong - attempting to save the file in the wrong place, or somehow misunderstanding what I'm supposed to do when saving a .asset file? 

I hope this post is some use.  Polybrush does seem like a really nice tool, and absolutely perfect for what I want to do. I hope there's some way I can use it on imported meshes being used as prefabs.

Share this post


Link to post
Share on other sites

 

10 hours ago, Ste Pickford said:

The data in the Z_Additional Vertex Streams field on this unselected object was gone ("None (mesh)"). I presume this is a bug?

Yes, that sounds like a bug. I've got a ticket open, but so far I have yet to reproduce on my machine. 

 

10 hours ago, Ste Pickford said:

Couldn't add object to asset file because the Mesh 'Cube' is already an asset at 'Library/unity default resources'!

That makes me think AssetDatabase is not reliably telling Polybrush what meshes are and are not a scene instance. That would also explain why you're not seeing the "Save to Asset" button on some meshes. I'll look into that - thank you again taking the time to write up your findings, it's a huge help when debugging these things!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×