Problems with emitting particles/effects from an entity since the latest update
6 replies, posted
Since the latest update for gmod, attempting to emit effects from entities results in error.
[B][U]Below is the critical points of the code:[/U][/B]
[CODE] function ENT:Initialize()
self.emitter = ParticleEmitter(self:GetPos())
[/CODE]
[CODE] function ENT:Draw()
local smoke = self.emitter:Add( "particle/smokesprites_0016", self:GetPos()) -- This is line 109
[/CODE]
[B][U]The error that is being thrown is:[/U][/B]
[CODE]
[ERROR] addons/mythic_servers/lua/fm/catch/stv.lua:109: Tried to use invalid object (type CLuaEmitter) (Object was NULL or not of the right type)
1. Add - [C]:-1
2. unknown - addons/mythic_servers/lua/fm/catch/stv.lua:109
[/CODE]
The issue seems to be that since the update, self.emitter doesnt exist when I attempt to create "smoke". So it throws a nil value. I cant see what would cause self.emitter to not be working since the update - it would appear to exist everywhere in the entity. Can anyone offer some advice as to what might be causing this issue?
No, it's because you're calling emitter:Finish() right after creating it, and since emitter:Finish() actually works now, it removes itself after all particles have faded.
Emitter:Finish() is pretty much like an Entity:Remove().
From now on only call it when you actually want to remove it.
Also emitters are properly garbage collected too now, so when your entity goes out of the PVS and gets "destroyed", the emitter dies too, so take that into account as well.
[QUOTE=Jvs;44442736]No, it's because you're calling emitter:Finish() right after creating it, and since emitter:Finish() actually works now, it removes itself after all particles have faded.
Emitter:Finish() is pretty much like an Entity:Remove().
From now on only call it when you actually want to remove it.
Also emitters are properly garbage collected too now, so when your entity goes out of the PVS and gets "destroyed", the emitter dies too, so take that into account as well.[/QUOTE]
I am never actually calling emitter:Finish() anywhere in the script. Mind elaborating on how you see I am finishing it right after creating it?
[QUOTE=Mythikos;44442811]I am never actually calling emitter:Finish() anywhere in the script. Mind elaborating on how you see I am finishing it right after creating it?[/QUOTE]
Sorry, was taking that into consideration as many people used to do that.
[QUOTE=Jvs;44442844]Sorry, was taking that into consideration as many people used to do that.[/QUOTE]
Ah gotcha. Thanks for trying :)
You are probably using the workaround for particle emitters which overrides the ParticleEmitter function.
Which should look like this:
[CODE]
if ( !PARTICLE_EMITTER ) then PARTICLE_EMITTER = ParticleEmitter; end
function ParticleEmitter( _pos, use3D)
if ( !IsValid( LocalPlayer( ) ) ) then return false; end
if(use3D) then
if ( !LocalPlayer( )._eParticleEmitter_3d ) then
LocalPlayer( )._eParticleEmitter_3d = PARTICLE_EMITTER( _pos, true);
else
LocalPlayer( )._eParticleEmitter_3d:SetPos( _pos );
end
return LocalPlayer( )._eParticleEmitter_3d;
else
if ( !LocalPlayer( )._eParticleEmitter ) then
LocalPlayer( )._eParticleEmitter = PARTICLE_EMITTER( _pos, false);
else
LocalPlayer( )._eParticleEmitter:SetPos( _pos );
end
return LocalPlayer( )._eParticleEmitter;
end
end
[/CODE]
Remove the function, always call Finish on the emitter when you are done and you should be good to go.
[QUOTE=syl0r;44443007]You are probably using the workaround for particle emitters which overrides the ParticleEmitter function.
Which should look like this:
[CODE]
if ( !PARTICLE_EMITTER ) then PARTICLE_EMITTER = ParticleEmitter; end
function ParticleEmitter( _pos, use3D)
if ( !IsValid( LocalPlayer( ) ) ) then return false; end
if(use3D) then
if ( !LocalPlayer( )._eParticleEmitter_3d ) then
LocalPlayer( )._eParticleEmitter_3d = PARTICLE_EMITTER( _pos, true);
else
LocalPlayer( )._eParticleEmitter_3d:SetPos( _pos );
end
return LocalPlayer( )._eParticleEmitter_3d;
else
if ( !LocalPlayer( )._eParticleEmitter ) then
LocalPlayer( )._eParticleEmitter = PARTICLE_EMITTER( _pos, false);
else
LocalPlayer( )._eParticleEmitter:SetPos( _pos );
end
return LocalPlayer( )._eParticleEmitter;
end
end
[/CODE]
Remove the function, always call Finish on the emitter when you are done and you should be good to go.[/QUOTE]
That was exactly my issue. I forgot I added the work around in the early stages of my addon. Thanks!
Sorry, you need to Log In to post a reply to this thread.