Skip to content

Commit

Permalink
Improved performance in 2019.2+ with a no-alloc version of GetComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
MileyHollenberg committed Jun 19, 2020
1 parent abe47dc commit 8ef4c8b
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,12 @@ static void PadZeroScale(ref float scale)

public static void SetupCollisionTester(MeshCollider collisionTester, Transform obj)
{
#if UNITY_2019_2_OR_NEWER
if (obj.TryGetComponent(out MeshFilter mf))
#else
var mf = obj.GetComponent<MeshFilter>();
if (mf)
#endif
{
var mesh = mf.sharedMesh;
if (mesh == null)
Expand All @@ -328,8 +332,12 @@ public static void SetupCollisionTester(MeshCollider collisionTester, Transform
return;
}

#if UNITY_2019_2_OR_NEWER
if (obj.TryGetComponent(out SkinnedMeshRenderer smr))
#else
var smr = obj.GetComponent<SkinnedMeshRenderer>();
if (smr)
#endif
{
smr.BakeMesh(BakedMesh);
collisionTester.sharedMesh = BakedMesh;
Expand Down

0 comments on commit 8ef4c8b

Please sign in to comment.