• entity clientside model issue
    7 replies, posted
I am making an entity that opens a derma, works fine, But i made a speechbubble above the head of the NPC, that works fine as long as i am spawning him in. If i permaprop the entity and restart the server, the speech bubble isn't there and it spits out errors. function ENT:Initialize() self.csModel = ClientsideModel("models/extras/info_speech.mdl") end function ENT:Draw() local bubbleAngle = (CurTime()*90) % 360 local bubbleHeight = math.sin(CurTime()*3) * 5     self:DrawModel()     self.csModel:SetPos(self:GetPos()+Vector(0,0,bubbleHeight + 90))     self.csModel:SetAngles(Angle(0,bubbleAngle,0)) end function ENT:OnRemove() self.csModel:Remove() end That is the code that is causing the errors. [ERROR] addons/npconjoin/lua/entities/mynpc/cl_init.lua:41: Tried to use a NULL entity! Error Any help on how to fix this would be appreciated.
I'd check the following things: Ensure you're running everything clientside Make sure you precache the model with util.PrecacheModel() Try wrapping the csModel stuff with an IsValid statement, in case there are calls made before the CSModel is loaded correctly: if self.csModel and IsValid(self.csModel) then -- csModel stuff end
Now it doesn't give me the errors but the speechbubble doesn't draw at all. This is my code. function ENT:Initialize() self.csModel = ClientsideModel("models/extras/info_speech.mdl") end function ENT:Draw()   self:DrawModel() if self.csModel and IsValid(self.csModel) then local bubbleAngle = (CurTime()*90) % 360 local bubbleHeight = math.sin(CurTime()*3) * 5     self.csModel:SetPos(self:GetPos()+Vector(0,0,bubbleHeight + 90))     self.csModel:SetAngles(Angle(0,bubbleAngle,0)) end function ENT:OnRemove() self.csModel:Remove() end end
You need to call self.csModel:DrawModel() in the ent draw function, and (probably) you should also use self.csModel:SetNoDraw(true) after creating the clientside model.
Try creating the CSModel (only if it's invalid) in ENTITY/OnDuplicated and/or ENTITY/OnRestore. I think Initialize doesn't get called in some situations, like what you described.
Nope, doesn't work. function ENT:Draw()     self:DrawModel()   if !IsValid(self.csModel) then    local bubbleAngle = (CurTime()*90) % 360    local bubbleHeight = math.sin(CurTime()*3) * 5     self.csModel:SetPos(self:GetPos()+Vector(0,0,bubbleHeight + 90))     self.csModel:SetAngles(Angle(0,bubbleAngle,0))     self.csModel:DrawModel()      self.csModel:SetNoDraw(true)   end  end
Anyone else might have a solution?
The easiest workaround is to check in ENT:Think whether self.csModel is valid, and if not, recreate it. If you want to dig deeper into why this even happens in the first place, I think you might have to do that yourself...
Sorry, you need to Log In to post a reply to this thread.