Skip to content

GeorgeAdamon/FastMeshCopy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FastMeshCopy

Zero-allocation copying of Meshes using the new MeshData functionality in Unity 2020.1+.

JULY 2025 UPDATE

  • Testedwith Unity 6000.0.52f1 LTS
  • BREAKING CHANGES:
    • Refactored the project structure to conform to Unity package naming and folder conventions. The package must be added using a different name and path (See below).
    • The CopyReplicate method no longer creates a new Mesh. It accepts a reference to a Mesh object, just like the CopyTo method.

API

The code comes in the form of the static class FastMeshCopy with the

public static void CopyTo(this Mesh inMesh, ref Mesh outMesh){...}

and

public static void CopyReplicate(this Mesh inMesh, ref Mesh outMesh, NativeArray<float4x4> matrices) {...}

extension methods.
Simply call this method on a Mesh instance to perform either a Single Copy, or a Multi-Copy based on an array of transformations + Merge.

Add as a Unity Package

Add this line to your Packages/manifest.json file

"com.ulc.fast-mesh-copy": "https://github.com/GeorgeAdamon/FastMeshCopy.git?path=/UnityProject/Packages/com.ulc.fast-mesh-copy#v2.0.0",

Usage of the Single Copy example

  • Attach the MeshCopyExample.cs to a GameObject, and reference a Mesh in the inMesh field.
  • Run the game, and press the Spacebar to perform the mesh copy.

Limitations

Accessing BlendShapes and BoneWeights without GC allocations is not supported by Unity's API, so this zero-allocation effort ignores them for the time being. See the discussion

Performance Example

Copying of a 98 MB mesh, creating only 80 Bytes of allocations for the Garbage Collector to clean-up.

About

Zero-allocation copying of Meshes using the new MeshData functionality in Unity 2020.1+ .

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages