OnEntityCreated problems

So I’m having a bit of trouble with this


I’ve been trying to use entity:GetPos() in my hooked func to get the position of entities created, but when I printed the results to console all I ever got was the origin (0,0,0). This happens no matter what kind of entity is being created. Is there any other way I could get the position of the entity while still using the OnEntityCreated Hook? (I need it for other things)

I think if this is called just after it was made, the position might not have been set before this hook is run.

so will I have to resort to a timer?
how much of a delay do I need?

Write in your code, and the error, then people might help you…

There is no error and the code is literally just GetPos() in a hooked function to OnEntityCreated

The “OnEntityCreated” hook is called on “vgui.Create()” and you can’t set an entity’s position before it’s created so it’ll always be at 0,0,0 in that hook. Typically the position is set directly after though, so a timer with a delay of 0 (1 tick) should work.

OnEntityCreated is called before it’s spawned or its position is set, a timer of 0.2 should usually do the trick.

I wish this hook passed the player who has tried to spawn it / if a player has.

Try **[Lua/Hooks/Sandbox/PlayerSpawnedProp](**

Doesn’t this only checks for prop_physics? I don’t think that is what he is making. But it’s worth a shot.

Thanks EvacX and arcane, I’ll probably try EvacX’s though because I’m mainly targeting env_explosion’s and need to grab their positions instantly.

If you had just clicked the link and checked all the similar hooks.


Those hooks wouldn’t work because they’re linked to the Q-menu; the ents I’m targeting are created from scripts

Besides he’s still likning to that broken wiki and most of those pages don’t have any text.

It should be fairly obvious how the hooks work without requiring a wiki page.

So EvacX’s timer method worked; I made a simple timer set to zero and it returns valid coordinates now.
However I have a new issue; I’ll post about it later when I get the chance.