Closed JR-Morgan closed 3 years ago
@JR-Morgan Great catch! In edit mode you have to call DestroyImmediate()
, I just submitted a PR that fixes that issue. But in the mean time if you need to implement a fix for that here is a handy function I use for destroying objects.
I also fixed the issue of the leaky meshes in that same PR. This was a new one for me since it usually asks for you to use a MeshFilter.sharedmesh
but that didn't seem to fix the issue when i was testing it prior. The fix seems to be that the mesh object needs to be built in an isolated fashion then assigned to the filter.
When receiving streams during editor mode. Many
GameObject
s are not cleared up and are left parent-less in the root of the scene hierarchy . (see Image)The following Unity error is printed to the console many times:
Destroy may not be called from edit mode! Use DestroyImmediate instead.
This is because, if the stream contains a
Base
where no children can be converted to a native object, Their correspondingGameObject
should be destroyed here: https://github.com/specklesystems/speckle-unity/blob/8a1e781e9e849132e960fa846f477359465e4e1e/Assets/Speckle%20Connector/RecursiveConverter.cs#L135-L139However, Due to running during Editor mode, The
Object.Destroy(Object)
function does not work as intended (a restriction imposed by Unity)I have drafted a potential solution to this here https://github.com/JR-Morgan/speckle-unity/commit/5a789f99568b1eeb52c0c2553b1287e48b344315#. Streams now properly import without leaving a bunch of empty and parent-less
GameObject
s. However, Unity is still complaining about another editor mode related issue (also present on main).Instantiating mesh due to calling MeshFilter.mesh during edit mode. This will leak meshes. Please use MeshFilter.sharedMesh instead.
Steps to reproduce
Clone speckle-unity main branch and open Unity Project. Add a
StreamManager
to any GameObject in the scene and import a stream that has nested non-native convertible objects. (eg. this stream https://speckle.xyz/streams/59185c5b8a Click Receive and wait for the editor dialogue to complete. Observe scene Hierarchy and console errors.