Removing Ents

How do you completely remove an entity. <entity>.Remove() doesn’t seem to actually get rid of it for good.

What do you mean by ‘doesn’t remove it for good’?

It should be <entity>


:

Remove( ).

You’re not removing anything if you don’t give it an entity to remove.

Assuming that is the problem, of course.


function PlaceSnaps()
	// put snap placement code here when done

	print(table.Count(ents.FindByClass("game_snap"))) //output:468

	local qPos = 0
	local tab = ents.FindByClass("game_snap")

	for key,q in pairs(tab) do
		qPos = q:GetPos()
		q:SetName("safe")
		for _,v in pairs(ents.FindInBox( qPos + Vector(-10,-10,-10), qPos + Vector(10,10,10) )) do
			if v:GetClass() == "game_snap" && v:GetName() != "safe" then
				v:Remove()
			end
		end
	end
	print(table.Count(ents.FindByClass("game_snap")))//output:468
end

I know that v:Remove() is getting run. In game I can see a lot of game_snaps disappear but they are still ‘somewhere’.

Your code is extremely confusing, but from what I can make up you first set the name of every game_snap entity to ‘safe’ and then you try to remove the ones which don’t have the name ‘safe’ which obviously results in 0 matches.

OK I have cases where when I place my game_snaps they overlap.

q:SetName(“safe”) - Doesn’t set them all to ‘safe’ before the nested loop. So if there are any game_snaps within the 10x10x10 Box of q they will get removed.

I placed a counter just below v:Remove() in the ‘if’ and it resulted in 283.

Well, your code does not make any sense whatsoever. What is it you’re trying to do? Remove every single game_snap?

No, remove the ones that are on top of each other. It works. All I wanted to know is how to permanently delete an ent.

EDIT:

It removed them completely from the beginning I just didn’t realize that they aren’t getting deleted till the function ended. Sorry to waste your time. thanks Overv.