SelectionBoxes are Disabling All Gui

While debuging my voxel library, it had became apparent to me that the voxels disabled all gui, including the CoreGui. From my extensive research, selection boxes were the problem. I have found that if you make a total of 22*30^2 (19800) SelectionBoxes with a LineThickness of 0.01, all Gui is completely invisible. Here are videos of the issue and their effects:
in studio:


in experience:

Currently, I have searched through a large portion of the devforum and I haven’t been able to find anyone with this similar issue nor a solution. The only two solutions I found is removing the selectionboxes entirely or increasing the SelectionBoxes’ LineThickness. Here is the code from my ModuleScript:

type VoxelLibrary = {
	description:string,
	
	voxelSize:number,
	chunkSize:number,
	
	bakingMode:number,
	
	overlapParams:OverlapParams,
	raycastParams:RaycastParams,
	
	renderFolder:Folder,
	
	baking:boolean,
	
	bakingModes: {[string]: number},
	
	currentVoxelMap:{{{number}}}?,
	BakeVoxelMap:(VoxelLibrary, Vector3)->({{{number}}}?)
}

local lib:VoxelLibrary = {
	description= "raycasting: uses more resources, more accurate. boundinbox: less resources, based on bounding box/selection box.",
	voxelSize = 2,
	chunkSize = 1,
	currentVoxelMap = nil,
	renderFolder=Instance.new("Folder", workspace),
	overlapParams = OverlapParams.new(),
	raycastParams = RaycastParams.new(),
	baking = false,
	bakingModes = {BoundInBox = 1, Raycasting = 2},
	bakingMode = 1,
	directions = {
		Vector3.new(1, 0, 0), Vector3.new(-1, 0, 0),
		Vector3.new(1, 1, 0), Vector3.new(-1, -1, 0),
		Vector3.new(1, -1, 0), Vector3.new(-1, 1, 0),
		Vector3.new(1, -1, 1), Vector3.new(-1, 1, -1),
		Vector3.new(1, -1, -1), Vector3.new(-1, 1, 1),
		
		Vector3.new(0, 1, 0), Vector3.new(0, -1, 0),
		Vector3.new(0, 1, 1), Vector3.new(0, -1, -1),
		Vector3.new(0, -1, -1), Vector3.new(1, -1, 1), 
		Vector3.new(-1, -1, -1),
		
		Vector3.new(0, 0, 1), Vector3.new(0, 0, -1),
		Vector3.new(1, 0, 1), Vector3.new(-1, 0, 1), 
	},
	
	BakeVoxelMap = function(self, bakingSize:Vector3):{{{number}}}?
		--if self.baking == true then return warn("already baking.") end
		local voxelMap:{{{number}}} = {}
		
		local voxelBakingSize:Vector3 = (bakingSize / self.voxelSize):Abs() - Vector3.one
		local voxelChunkSize = bakingSize/self.voxelSize/self.chunkSize
		print(voxelChunkSize)
		
		local renderVoxelSize:Vector3 = Vector3.one * self.voxelSize
		
		--self.baking = true
		
		for chunk=1, self.chunkSize, 1 do
			local offset = Vector3.new(voxelChunkSize.X*(chunk-1), 0, voxelChunkSize.Z * (chunk-1)%(self.chunkSize*.5))
			--local chunkPart = Instance.new("Part") do
			--	chunkPart.Size = voxelChunkSize
			--	chunkPart.Position = offset
				
			--	chunkPart.Parent = self.renderFolder
				
			--	chunkPart.Anchored = true
			--	chunkPart.CanCollide = false
				
			--	chunkPart.Transparency = .8
			--end
			--print(offset)
			for x=0, voxelChunkSize.X, 1 do
				local row = {}
				for y=0, voxelBakingSize.Y, 1 do
					local column = {}
					for z=0, voxelChunkSize.Z, 1 do
						local position = (Vector3.new(x,y,z)-(voxelBakingSize*Vector3.new(1, 0, 1)*.5))*self.voxelSize + offset
						local depth = 0
						--local thing
						
						if self.bakingMode == 1 then
							if #workspace:GetPartBoundsInBox(CFrame.new(position), renderVoxelSize, self.overlapParams) > 0 then depth = 2 end
						elseif self.bakingMode == 2 then
							for _, direction in self.directions do
								local cast = workspace:Raycast(position-direction*(self.voxelSize*.51), direction*(self.voxelSize*1.02), self.raycastParams)
								if cast then depth = 2 break end
							end
						else
							depth = 2
						end
						
						if depth>0 then
							local p = Instance.new("Part") do
								p.Position = position
								p.BrickColor = BrickColor.random()
								p.Anchored = true
								p.Parent = self.renderFolder
								p.Size = renderVoxelSize
								p.CanCollide = false
							end
							local selectionBox = Instance.new("SelectionBox") do
								selectionBox.Color3 = Color3.new(0,0,0)
								
								selectionBox.LineThickness = 0.01
								
								selectionBox.Adornee = p
								selectionBox.Parent = p
							end
						end
						
						table.insert(column, depth)
					end
					table.insert(row, column)
				end
				task.wait()
				table.insert(voxelMap, row)
			end
			task.wait()
		end
		
		--self.baking = false
		return voxelMap
	end
}

--lib:BakeVoxelMap(Vector3.new(100, 100, 100))

return lib

If you have any solutions other then removing or changing the LineThickness of the SelectionBoxes, please share them!

1 Like

It looks like you are hitting the limit of your graphics card and your graphics settings are just saying ‘nope’.
Is it possible to only have the outer layers of boxes be rendered. You don’t need to render any that aren’t being shown.

1 Like

Yes I agree, Seeing roblox seemingly freeze in the second clip probably means you are overloading something. I have experience generating tens of thousands of baseparts, but it seems like selection boxes share some kind of limit with the gui. As you can see in the first clip, the gui dissapears as soon as the new parts being made stop getting their selection boxes.

1 Like

This is highly possible, but the graphics card can render roughly up to a million stationary parts with minimal buffers. WIth that in mind, Roblox’s part rendering system might more optimized than rendering 12 lines consecutively…

Yes, it is possible for the outerlayers to be rendered and I plan to optimize the rendering in the near future.

1 Like

I did come up with a theory that is extremely similar with that. Maybe there is a limit to how much interface can be rendered.

1 Like

If you look up posts about Highlights it seems that they only allow 31 at a time before capping those. I imagine SelectionBoxes would have a cap too.
Raise limit on the number of active Highlights

2 Likes

I have noticed that limit in highlights while experimenting with other projects. I didn’t realise the limit was that low! Thank you for telling me this information.

I do believe the SelectionBox limit is, in some way, intertwined with rendering the interface. It does allow the SelectionBox limit valid, since the closer the camera is to the part, the more visible the lines are. This becomes most visible in studio when the SelectionBox reaches the said limit. This ‘filtration’ system is similar to Beams and how distance effects their visibility.

1 Like