Game Development Community

T2DParticleEffect & cloning

by Kzoink · in Torque X 2D · 07/26/2007 (12:47 am) · 1 replies

I made a template of a T2DParticleEffect to clone and use multiple times. Once I make the clone/copy, I access and use the CurrentEffectData property and the EmitterDataList to control the particle effect dynamically at runtime. This works great if there's only one T2DParticleEffect, but the minute I use clone to make a copy, both particle effects get an internal reference to the same T2DParticleEffectData instance in the CopyTo function and that has the undesired effect of my dynamic manipulation of its data affecting both unique instances of the T2DParticleEffect class at the same time.

Question: Is there a better way I haven't thought of, or am I going to have to create a unique instance of the T2DParticleEffectData class myself, copy over all the variables, and assign it to the CurrentEffectData property after the clone?

It seems like the particle system was not designed for dynamic runtime manipulation due to its shared data, but I really need to have unique instances of the variables that drive the emitters in order to support certain types of dynamically-controlled effects in my game. It would definitely be nice if it was configurable whether to share the data or instance it when cloning.

#1
07/26/2007 (2:57 am)
I did solve the particular problem by doing what I described, but it was not very fun to copy all of the stuff from T2DParticleEmitterData. That's a ton of fields...

I kept some of the data as references and made new instances of what data I needed to be instanced. I guess I will have to do this for all particle effects I want to be driven dynamically and create a new instance of whatever variable I want to tweak after I clone it.

I would like to know if anyone has any suggestions about how the engine could handle this type of situation a little more elegantly. That is, how to choose which variables to instance and which to simply reference between different objects when cloning them.