I apologize for the long post. My goal is to link my subsystem that manages projectiles to particles one-to-one.
And there are two problems here:
- I can not assign particle ID (even with persistent ID on) to my projectile when I create new projectile, while with AActors I can easily do that and assign weak pointer to it. Thats becasuse Niagara and main game run in different threads, and particle for projectile would be created later in “Emitter spawn” stage, after all non thread safe operation completed (when work with data interfaces is done).
- After I have more then 64 particles they keep constantly changing index in “Particle update” stage and I do not know any way to have constant sequence.
Projectiles in my subsystem also change their index: lets say I have n projectiles in array and i projectile should be removed. I would rewrite n projectile to i position and whole array would shrink to n-1.
So I have few ideas.
- Generate projectile ID in my mananger and pass it to Niagara. I would have to get it next frame and I do not know the way to get it fast like with build in function “Get particle by ID”. So to do that I have to run throught all particles every execution. In terms of O-notation its expensive N^2.
- Make a custom data interface, not sure it would help somehow except I could send my data in one go with array of type “projectile” instead of multiple arrays.
- Make my projectiles index in manager to be constant and never change it. In this case instead of removing unused projectiles I can mark it as unused with bool so all indexes remain same.
Create same num of particles in Niagara and disable kill state. In “Projectile spawn” stage save their first time execution index to be a constant index for adressing Array from data interfrace. Bulky and would add some real overhead but that could work. - Another option is trying to sync projectile manager to Niagara IDs by sending a list of particles to be created, list of particles to be updated and deleted separately. Then I would need to get a response back with list of sucessfull operations. Like a web API, crazy
I know that it is possible to change Niagara C++ code to get the required result, it was done by one smart guy. But this looks impossible to my skills right now. May be there are any other options? May be there is a way to make particles keep their execution index from frame to frame somehow?
Or maybe there is a way to get benefit of mesh instantiation on GPU without Niagara somehow? In this setup Niagara is useless layer because I dont need the simulation but only effective mesh renderer.
Would be grateful to any ideas. Stuck with it for a few month.