Humanoids and CollisionGroups, why am I losing frames?

A while back I posted something about this, but I didn’t actually include a repro.
Repro.rbxl (47.9 KB)

What I’m doing;

  • Spawning 50 Humanoids
  • Setting all of their parts to one CollisionGroup, excluding a Capsule if it exists
  • Disabling all unneccesary states; eg climbing/swimming
  • Telling that CollisionGroup that it can’t collide with itself.
  • Have the enemies chase me

After a few seconds I begin to lag out hard as they start to overlap. This is extremely prevelant in non-default characters, however it also happens to default characters in some edge cases.

You can change the model that is being used by changing the path it grabs them by in the StarterGui script. Change it to any other name in the Replicated Storage.

Theories for why this might be happening;

  • Shadows; I’ve just added all my custom npcs, which use CFrame and a ray whitelist, into a Model that has a humanoid, while they were clustered frames drop to 20-30, but once they seperate it goes back up to 60.
    Link here
    (I have tried this in the most recent Future is Bright demo build, there doesn’t seem to be much difference in performance in regards to this issue. This is a negligable theory.)

  • Collisions; Possibly still checking if they collide with eachother despite being in a non-collide Group.

If you could look at the repro and see how you fair with different models it would be appreciated!

9 Likes

I use CollisionGroups in this same manner and don’t ever lag. Gameplay remains smooth. Your problem is most likely the Shadows.

1 Like

There is a repro attatched, would you be able to look and see what differences you come across?
I was worried about it being shadows too, however when I use a Capsule model to stop them overlapping one another there is still a significant frameloss

1 Like

Oh, oh boy, I might’ve misread the post. I read one part of it and said “hey, I use collision groups too!”.

The way I use collision groups is setting all the parts of a character to a collision group, that’s about it. I can link a full chunk of code I use in my game in reference to that:

--[[
	SpecialRegion.lua
	// Author: colbert2677
	// Summary: Handles a special region on the map
--]]

local IsHighRank = {}

local function SetPartsCollisionGroup(Part, CollisionGroupName)
	-- Sets the collision group of the Part to the second parameter, then calls the function on its children
	local PhysicsService = game:GetService("PhysicsService")
	
	if Part:IsA("BasePart") then
		PhysicsService:SetPartCollisionGroup(Part, CollisionGroupName)
	end
	
	for _, Child in next, Part:GetChildren() do
		SetPartsCollisionGroup(Child, CollisionGroupName)
	end
end

do
	-- Set up collision groups and collidability for slated objects
	
	local PhysicsService = game:GetService("PhysicsService")
	local RegionName = "ExecutiveLoungeRegion"
	local Region = workspace:WaitForChild(RegionName)
	
	PhysicsService:CreateCollisionGroup("HighRanks")
	PhysicsService:CreateCollisionGroup("HighRankRegions")
	
	PhysicsService:CollisionGroupSetCollidable("Default", "HighRanks", true)
	PhysicsService:CollisionGroupSetCollidable("HighRanks", "HighRankRegions", false)
	
	PhysicsService:SetPartCollisionGroup(Region, "HighRankRegions")
	
	Region.Transparency = 1
end

do
	-- Set up characters for the regions
	
	local Players = game:GetService("Players")
	
	Players.PlayerAdded:connect(function (Player)
		IsHighRank[Player] = Player:GetRankInGroup(2957840) >= 11
		Player.CharacterAdded:connect(function (Character)
			if IsHighRank[Player] == true then
				SetPartsCollisionGroup(Character, "HighRanks")
			end
		end)
	end)
	
	Players.PlayerRemoving:connect(function (Player)
		IsHighRank[Player] = nil
	end)
end

return nil

But that’s probably not what needs to be accomplished here.

I did open up the repro place, results are here. I didn’t seem to experience any lag when they were constantly overlapping. Don’t know if the way they move in that GIF is intended or not.

I’m going to sit on the possibility that your rays might be causing the problem, but after giving this post a deeper read I realize I don’t have a clue what I’m talking about.

1 Like

Stand on top of their heads for a bit (~30 seconds). You’ll get a huge performance drop.

(I noticed you have a Top Contributor badge :ok_hand:)

  • NoCollider instantly dropped my frames.
  • Collider took ~3 seconds to drop my frames.
  • DummyR15 didn’t drop my frames at all.
  • DummyMesh didn’t drop my frames at all.
1 Like

I’ve also been unable to replicate

Has something to do with the collision physics being ran here. I opened a new place and dropped 50 colliders around the map randomly; no lag or frame drops.

It could be all the meshes. When testing the types of avatars

I got the same results.
Perhaps there is an issue with CollisionGroups and custom meshes?

1 Like

Odd, using DummyMesh I get < 10 frames when standing on their heads:


1 Like

Using DummyMeshes, I got no lag whatsoever, even after a good minute.

Can you create a startercharacter using a default (block) rig and disable character appearance?
If it is meshes, this could be a method of testing

With both the default block appearance for R6 and R15, I get < 10 frames a second.

I think I’m starting to see whats happening;

Just as they are touching

When they are all touching

After Anchoring all their parts

This resloves the theory about shadows being the cause atleast
(I keep forgetting the micro-profiler!)

making them collide with each other is the only solution i’m familiar with.

(on a low end machine) changing the collision fidelity of collider to hull reduces lag significantly, changing the collision fidelity to box eliminates the lag

i’d suggest using a tightly-fit bounding box in order to get the best combination of collision and preformance results

I just tried changing the collision fidelity and it eliminated it almost entirely.
Oddly, without doing this, having all the units occupy one space, Anchoring all parts removes the lag, having only the Root removes the lag. But it removes it seemingly perminantly.

The CollisionFidelity of the DummyMesh is already Box and I still have performance issues.

1 Like

i just tested for the overlapping noncollider case and it’s lagging me badly, and changing the collision fidelity of the models doesnt seem to effect preformance

Small mistake I found was the Collisions that are already enabled within the models and not all collisions were set to Box, some were left on Default (not quite sure how.)
I’ve altered this and now the NoCollider seems to run smoothly, however the Collider still have issues.