Hakim Posted September 9, 2022 Share Posted September 9, 2022 (edited) Hello, After instantiating a particle effect that isn't tied to a persistent object and lasts a finite amount of time (for example, sparks when a bullet hits a wall), how do I know when to destroy it? There doesn't appear to be any sort of property or callback in the ObjectParticles interface that could be used to determine whether it's no longer emitting particles. The Third Person Platformer demo in the SDK just loads a node, places it and forgets about it, which is fine for a demo, but having an unbound number of no-longer useful nodes remain in memory until potentially the end of time strikes me as something that would cause problems eventually. I tried writing a function that tries to calculate the total lifetime of a node from the properties of the ObjectParticles it's made up of, but because there are multiple ways of preventing it from running forever and most effects are made up of multiple emitters, some of which may be synced to others, it's difficult to make robust. Is there anything I missed in the API or am I just going about this the wrong way? Edited September 13, 2022 by Hakim Solved Link to comment
tarragrum Posted September 12, 2022 Share Posted September 12, 2022 Hi, Third Person Platformer demo have component Destroy. This component look after nodes lifetime and invoke deleteLater(). If you want decrease allocations amount, you can use object pool pattern 1 Link to comment
Hakim Posted September 13, 2022 Author Share Posted September 13, 2022 So it basically boils down to either manually specifying the lifetime somewhere or using a fixed pool of nodes and using them as needed in a round-robin fashion? I suppose I was expecting something that could be extracted from the nodes directly, but those solutions are workable. Thanks! Link to comment
Recommended Posts