Community Forum

Modify particle parameters from LUA code

Forum Overview >> Scripting

Created20.04.2021 13:37

Simone Santillo (Sismo) 20.04.2021 13:37
Hi all!
I am new to modding although I know some LUA from past experiences, so I hope I am asking this question in the proper forum section.

I have successfully created a particle effect from the editor and was able to place it into my map. I was also able to customize all the properties of such particle effect through the "Particle effect" window inside the editor - no problems up to here.

Now I wonder whether it is possible to change the particle effect parameters (e.g. scale, scale gain, gravity and so on) directly from the LUA code at game time.

Thanks in advance to anyone who can provide pointers to code snippets or other mods able to achieve similar results (so I can peek into their code and learn how to do it!).


Bilbo Beutlin (BBeutlin) 20.04.2021 15:17
You'll find already many code snippets in the LUADOCs, eg. in the vehicle specialization scripts where effects are used.
Common to all is, you cannot change at runtime certain parameters, since the effects are almost all done by shaders which require compiling. This is done once at initialization.
That means if you want to change parameters, you have to stop or reset the effect at first before you start again with other parameters.

Simone Santillo (Sismo) 21.04.2021 09:08
Thanks for the prompt response!
I'm trying to figure out where exactly are placed the snippets of "vehicle specialization scripts where effects are used". I cannot find them in the Documentation section.
I have further question, just to be sure that I understood it well: "you have to stop or reset or reset the effect" this means I should exit from the game and reload it, right?

Simone Santillo (Sismo) 21.04.2021 09:19

Bilbo Beutlin (BBeutlin) 21.04.2021 12:56
Look in LUADOC/Script/Specializations. Certainly you need to know in which spec effects are used.

Instead searching here on GDN you may DL and install the Giants Remote Debugger. It comes with archives of FS LUA scripts. You may unpack an archive, so you can search easily eg. with Notepad++ "search in files" for certain key phrases.

Of course I didn't mean to restart the game, but the effect. This is mostly handled by the EffectManager to load, start, stop, reset effects. See appropriate docs in LUADOC/Script/Effects.

Simone Santillo (Sismo) 26.04.2021 13:52
Thanks for the pointers!
I installed the Giants Remote Debugger and I'm trying to get confident with it.. now I have two questions (posting here to avoid flooding the forum):
1) It seems that breakpoints are not working: no matter if I start the game from the debugger or on its own, the breakpoint is not considered (but the line is executed since i see the print result)
2) The particle I've created consists of a Transform Group inside my map. How can I retrieve its node from my LUA script?

Thanks for the patience!

Bilbo Beutlin (BBeutlin) 26.04.2021 14:54
Well, I must admit I didn't work much with the debugger. So I can only advise to the guide here on GDN:

To identify a transform in your map you can either use directly its nodeId (Transform -> Id) or its 'Index Path' where you get the nodeId with 'I3DUtil.indexToObject(rootNode, index)'.

Simone Santillo (Sismo) 28.04.2021 12:22
Hi Bilbo!
Thanks again for your support.

I am still stuck now but on a different matter:
I do have the nodeId of the particle system but now I want to pause it / freeze it without removing it from the rendering.

I am not able to access any of the particle system call methods given the nodeId (not sure if this would help anyway);
I have tried to call removeFromPhysics() on a parent node but that does not seem to affect the particle system although it's flagged as rigid body...

Do you have any hints on the matter?

Thanks in advance,

Bilbo Beutlin (BBeutlin) 28.04.2021 15:27
If you look into the LUA source codes: the effect controls don't work with i3d object nodes or ids, but with pointers to the effect tables. That means you must lookup where to get these entries from functions in LUADOC/Script/Effects or LUADOC/Engine/ParticleSystem.

Note: Log in to post. Create a new account here.