Entity Spawning

I’m trying to make an entity spawn, but it freezes in air, it accepts physgun but doesn’t move anywhere.

[lua]
function ENT:Initialize()
self.Entity:SetModel(“models/error.mdl”)
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)

local phys = self.Entity:GetPhysicsObject()

if phys and phys:IsValid() then phys:Wake() end
self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE_DEBRIS) 

end
[/lua]

Here’s my spawning code:

[lua]
local ent = ents.Create(“gm_item”)
pos.z = pos.z + 15
ent:SetPos(pos)
ent.dt.amount = a
ent.dt.class = class

ent:Spawn()
ent:SetModel(i.Model)

[/lua]

The model shows up fine, but just floats.

[editline]17th July 2011[/editline]

If I make the entity wake instantly, I get this error

[---------------------------------------:–] Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type)

Try setting the model before you spawn it.

Fixed, thanks