Managing particle systems depending on scene whilst remembering state
Hi, guys! Hoping I could get some help on an issue I've been struggling on for some time.
I have two rooms. A kitchen and a hallway; two separate scenes. I also have particle systems in each room in the form of fires and smoke. And to manage these fires, I have a FireManager. Now, the GameManager cues the FireManager for when the fire should start. The FireManager has already instantiated the fires in Awake(), and then it just .SetActive(true) on the two fires, when the GameManager calls for them to start.
Let's say I stand in the kitchen when the fire starts. I see the fire develop a bit, and then enter the hallway where the fire hasn't started yet. And then I enter the kitchen again. Now, the flames should have grown a little in the time I've been in the kitchen. And there should also be more smoke in the kitchen.
And this is where the problem/trade-off lies.
1) If I disable fires depending on which room I am in, i.e. disabling kitchen fire when entering hallway, and then re-enable kitchen fire when re-entering, the kitchen fire starts at the beginning again.
2) If I keep both fires enabled throughout, the particle system from one room will enter the other room, i.e. the flames from the kitchen comes through the wall and into the hallway.
So, basically my question is how would I go about managing these fires so that either
1) the states of the fires are managed whilst using .SetActive (or any other method for that matter)
2) Keep the flames contained within their respective room/scene.
Note : It is probably worth mentioning that these fires contain several fire particle systems within themselves. At root there is an empty gameobject, which contains gameobject containers for different types of fires. i.e. an empy gameobject within the fire hierarchy called "Small Fires" which have script components for scaling and moving the fire, and underneath that object, the actual fires reside. If that makes any sense. Not sure if that is relevant for the question though.
Note 2 : I've looked at the Simulate - function, but I haven't been able to implement it successfully. Because how would the FireManager be able to tell the fires to simulate? I can't make the FireManager call internal functions on the fires, so I don't know FireManager would be able to tell the fire "Hey, someone entered the room. Start simulating the fire as 10 seconds has elapsed".
Note 3 : This is to run on android and iOS mobile phones with the use of VR, so performance is a key issue here.
I'm reeeally hoping for more than a once-sentenced answer, but I'll take anything I get at this time :)
Answer by Glurth · Apr 27, 2016 at 05:43 PM
I would suggest that you use your METHOD 1 above, where you disable the fire depending on the room you are in. However, rather than enable/disable the particle systems using SetActive(), I would suggest you use the ParticleSystem PAUSE function, which should allow it to continue from where it left off. Alas, I do NOT know if anyway to disable the DISPLAY of a paused particle system (simply disabling it causes it to restart, even if paused. I guess you could always do somkind of workaround, like move it far away, out of view.)
An alternative would be to use the GetParticles and SetParticles functions of the ParticleSystem class, to save, and then reinitialize the state of the particles.
Your answer
Follow this Question
Related Questions
Game state management & and passing data between scenes -1 Answers
garbage collection in between scene changes? 2 Answers
Restarted scene not working properly 0 Answers
After reloading the scene twice one script doesn't work. 0 Answers
Loading and Unloading scenes 2 Answers