Changing CollisionFidelity of Union at runtime?

Is it possible to change the CollisionFidelity of a union at runtime?


With a MeshPart, you can re-generate it with asset service,

local NewMeshPart = AssetService:CreateMeshPartAsync(
            Content.fromAssetId(NumberId),
            {
                RenderFidelity = Enum.RenderFidelity.Automatic,
                CollisionFidelity = TARGET_COLLISION_FIDELITY,
                FluidFidelity = Enum.FluidFidelity.UseCollisionGeometry,
            }
)
        
MeshPart:ApplyMesh(NewMeshPart)

but with Unions there’s no :ApplyMesh method. Although, there’s a lot of functionality with unions I don’t have much experience with, so I’m thinking it is possible, but just in a different way

It doesn’t seem like there is a way. A hacky way to do this is to have multiple copies of the union with different collision fidelities, and swap them out when you need it changed

Might I ask why you would do this?

I ended up figuring it out; just reunion solely the union which allows you to use a new CollisionFidelity

For anyone curious, here’s the entirety of my module. It allows you to change usually un-changeable instances CollisionFidelity at runtime:

(pcalls may be needed, so keep that in mind since I haven’t done that yet)


--!strict
-- Written by @baseparts

local AssetService = game:GetService("AssetService")

local function AssetStringToNumber(AssetId: string): number
	return string["match" :: any](AssetId, "%d+$") -- this is ugly but avoids intellisense warning
end

local ClassToFunction = {
	["MeshPart"] = function(Mesh: MeshPart, TargetCollisionFidelity: Enum.CollisionFidelity)
		local NumberId = AssetStringToNumber(Mesh.MeshId)		
		local NewMeshPart = AssetService:CreateMeshPartAsync(
			Content.fromAssetId(NumberId),
			{
				RenderFidelity = Enum.RenderFidelity.Automatic,
				CollisionFidelity = TargetCollisionFidelity,
				FluidFidelity = Enum.FluidFidelity.UseCollisionGeometry,
			}
		)

		Mesh:ApplyMesh(NewMeshPart)
		return Mesh
	end,
	["UnionOperation"] = function(Mesh: UnionOperation, TargetCollisionFidelity: Enum.CollisionFidelity)
		local Union = Mesh:UnionAsync( {Mesh}, TargetCollisionFidelity, Enum.RenderFidelity.Automatic )
		
		return Union
	end,
}

return ClassToFunction