Effects / Emiters cleanup question

Been going around in circles with emitters recently and unable to come to a definitive answer. Case in point, I've a unit that creates an attached emitter like so. Saving it to a table "self.ThrasherFXBag" for later use...

table.insert(self.ThrasherFXBag, CreateAttachedEmitter(self, 'exhaust', self:GetArmy(), '/effects/emitters/missile_smoke_exhaust_02_emit.bp'):ScaleEmitter(0.5))

self.Trash:Add(self.ThrasherFXBag)

Later I want to destroy the emitter and call this function...

FXCleanUp = function(self, whocalled)
	local myDebug = true	
	if myDebug or mainDebug then WARN('UEA0206 FX Clean Up: ', whocalled) end

	--Destroy Afterburner FX
	if self.ThrasherFXBag and table.getn(self.ThrasherFXBag) > 0 then
		if myDebug or mainDebug then WARN('self.ThrasherFXBag > 0 ') end
		for k, v in self.ThrasherFXBag do
			if myDebug or mainDebug then WARN('Destroying v') end
			v:Destroy()
		end
	end
	if myDebug or mainDebug then WARN('self.ThrasherFXBag size after destroy: ', table.getn(self.ThrasherFXBag)) end		
end,

My log is showing...

WARNING: UEA0206 FX Clean Up: 	Afterburner 1
WARNING: self.ThrasherFXBag > 0 
WARNING: Destroying v
WARNING: self.ThrasherFXBag size after destroy: 	1

So based on the log someone could assume that nothing is being destroyed?

or

Is the emitter being destroyed, but the table is not cleared after each instance is removed?

Side note: I've also notice that not all emitters are capable of be scaled. No idea why this is or what criteria determine this. By chance anyone know?

-Resin

Calling Destroy method on it will destroy it, but it wont remove it from a table you've added it to. Its gonna be there, just destroyed.

If ThrasherFXBag is of type TrashBag then the reference is, eventually, also removed from the table by the garbage collector.

A work of art is never finished, merely abandoned

@resin_smoker said in Effects / Emiters cleanup question:

Side note: I've also notice that not all emitters are capable of be scaled. No idea why this is or what criteria determine this. By chance anyone know?

All emitters can be scaled, do you have a concrete snippet that can not scale according to you?

A work of art is never finished, merely abandoned

Was attempting to scale simple beam emitter. I believe it was with CreateAttachedBeamEmitter(). Meanwhile, I could alter the beamFX lifetime and a few other things, just couldn't not use SetScale().

Edit: Will post a code snippet next time I'm using the computer.

uea0206_Script.zip @jip

table.insert(self.ThrasherFXBag, CreateBeamEmitterOnEntity( self, 'afterburner', self:GetArmy(), '/mods/4DFAF/effects/emitters/uea0202_afterburner_fire_beam_01/uea0202_afterburner_fire_beam_01_emit.bp'):SetEmitterParam('Lifetime', burnTime))

Above is what I'm currently using, which works, minus being able to re-scale it. However, please note that I'm currently using a custom file so i can manually change the scale.

Using :SetScale(Value) doesn't appear to change anything. Neither does :SetEmitterParam('Thickness', value) or :SetEmitterParam('length', value), which "Thickness" and "Length" are BeamBluePrint values that can be seen via a repr() of the emitter file.

(Effect file shown below, length and thicknesses are half the original files values)

-----------------------------------------------------------------------------
--	File		: /4DFAF/effects/emitters/uea0202_afterburner_fire_beam_01/uea0202_afterburner_fire_beam_01_emit.bp
--
--	Author(s)	: EbolaSoup, Resin Smoker, Optimus Prime, Vissroid
--
--	Summary		: Special FX for use with Thrasher multirole fighter
--
--	Note		: This file is needed as the default GPG beam effect can not be rescaled via :ScaleEmitter()	
--
--	Copyright © 2024 4DFAF, All rights reserved.
-----------------------------------------------------------------------------

BeamBlueprint {
	Lifetime = 3.0,
	TextureName = '/textures/particles/missile_exhaust_fire_01.dds',
	Thickness = 0.05,
	StartColor = {x=1,y=1,z=1,w=0.2}, -- R,G,B,A
	EndColor = {x=0.0,y=0.0,z=0,w=0}, -- R,G,B,A
	Length = -1.4,
	UShift = 0.0,
	VShift = -0.65,
}

If your iterested or need to see the units complete .lua for context, Ive included it below. The script does run as intended, which is pretty good for a guy who hasn't scripted in 10 years.

uea0206_Script.zip

Ah, I understand now. Not all emitters are alike, in Supreme Commander we have:

  • (1) Actual emitters
  • (2) Trails
  • (3) Beams

You can scale (1) just fine. But (2) and (3) have a similar class, but not everything works on that class. It never did, that's not something we changed. For more information, see also:

And specifically SetBeamParam for beams. I'm not sure how to adjust trails in Lua.

A work of art is never finished, merely abandoned

@jip ahh that Github helps clarity things... What I noticed right off is that I used "Length" where the Github has "LENGTH" with all capitals. Will attempt this later and post back the results.

Which, looking (again) at the emitter blueprint, it doesn't say specifically which type of emitter it is. (It's name does but not within the BP) Thus, its likely being defaulted by the effects Lua some where down the pipe. Figuring out which type is it, will help provide a solution or a possible path to one.

Side note: Would be helpful to be able to update the Lua Wiki to reflect this. As is the reference has a few holes.

I'm wondering is changing from "CreateBeamEmitterOnEntity()" to "CreateEmitterOnEntity()" would work using the same file. (Or is it CreateAttachedEmitter ? )

@resin_smoker said in Effects / Emiters cleanup question:

Side note: Would be helpful to be able to update the Lua Wiki to reflect this. As is the reference has a few holes.

What Lua Wiki?

It's best to use the references and documentation in the repository directly, the annotations have been in the works for the past two to three years and is still being improved occasionally 🙂

A work of art is never finished, merely abandoned

"LENGTH" results in... "WARNING: Error running lua script: Invalid Effect Parameter LENGTH"

"Length" results in... "WARNING: Error running lua script: Invalid Effect Parameter Length"

Using "CreateAttachedEmitter" with the Beam blueprint results in... "WARNING: Failed to create emitter as you passed in an invalid blueprint name /effects/emitters/missile_exhaust_fire_beam_01_emit.bp."

Kinda figured that would happen, but was worth trying it just to know for sure.

-Resin

@Resin_Smoker better to review this folder:

It has all the information on the wiki and more 🙂 . We should probably link the Wiki to that

A work of art is never finished, merely abandoned