Elemental Rendering Problem

 Author: Yashwant Patel


The Problem

This week I was tasked with creating and implementing a wave system that would spawn enemies in all three lanes based on a weight given to the lane and based on the weight of the enemies for a particular weight. This makes it nice to fine tune individual waves and the implementation mostly went without a hitch. Although there was one giant problem that stuck out like a sore thumb or in this case it really didn't stick out and it should've. Our two enemy types use a particle currently as their model and when the elementals are spawned, but due to some internal workings of Unreal (or maybe a bug) they wouldn't render in when initially spawned. What's the point of a wave system if all the enemies are invisible? If we were going for a game where enemies could turn invisible or were invisible then this would've been fine, but we aren't, so it is frustrating for the player to try and gauge the location of the enemy using the health bar above their heads.


As you can see from the video it's frustrating to shoot enemies that are invisible and this is exactly the bug we ran into. I did land most of the shots, but that's because usually the developers are the best players when the game is in development.


The Solution

The solution was pretty straight forward after it was figured out, but getting to the solution was a long journey. This bug started in the previous build, but we were unable to track it down since in that build the enemies weren't spawning in (they were simply placed in the scene), so sometimes they'd render and sometimes they wouldn't. Inconsistent bugs are always one of the harder types to track down. After implementing the wave system all the enemies are spawned in at runtime which meant somehow the particle system was either not getting baked, something with shader compilation, some settings were causing it to not render (culling), or something unknown to us at the time. After doing research I tweaked a bunch of settings mainly that had to do with rendering. The first solution that worked for other developers was to have the particle system use a fixed relative bounding box for rendering and culling calculations. This made it so it wouldn't recalculate the bounding box every frame which is nice and performant and that ended up fixing the bug for other developers, but for us it didn't work. After that I took a look at a bunch of settings on the particle component itself in the blueprint editor such as seconds before inactive (number of seconds emitter isn't rendered and that need to pass before it no longer gets ticked), LOD methods. never distance cull (bool), HLOD (auto LOD generation), but none of these changes had any sort of effect. 

After more fiddling I was able to actually get the elementals (particles) to render, but that was only after I pressed reset emitter in the details panel after the elemental had spawned. The downside being you can't manually sit there pressing reset emitter through the editor when someone is playing, so there has to be a function that resets the emitter right? Well after looking at the documentation couldn't really find a 1 for 1 function that would do that, so instead I tried the hacky way that I thought would yield results. I set the component inactive with the reset bool active and then set it active again to try and restart the particle component. This however didn't work. Next function that was tried was set emitter enable, which sounded promising, but that didn't work either. After that I decided to take this problem to the Professor and we tried mostly all the previous solutions that were tried before, but no luck. 

After not getting it to work the Professor recommended a different approach of doing spawning know as a Pooling System. This is a great system and design pattern to recycle objects / data, so you constantly aren't allocating and deallocating memory. We did a small test of a semi-working Pooling System where the enemies are placed in the map manually (where the player can't see them) and then when they need to be spawned they just get moved to the starting location and after dying they get moved to a place where the enemy can't be seen or turned off (so they aren't rendered). This is definitely a great system to have, but it takes a little time to get up and running and having to refactor the code would add extra time which we didn't really have since it was build day. I've done a Pooling System before (where it would spawn enemies as needed if there weren't any available in the pool or just use the available ones without spawning new ones), but I didn't want to rush and quickly make a hacky one to just remake it again. So I decided to save the Pooling system for the very last resort and gave myself a 30 minute time limit to fix the issue. I tried to see if there was any other forum or article that I had missed by googling the problem once again, but no luck. After that I fiddled in the blueprint editor and stumbled upon this node.


With no other options in sight I set a delay until next tick and then ran this function after all the other functionality had been run on Beginplay. 


Thankfully this worked! So I luckily stumbled upon this node and either this is a bug in Unreal or the particle components need to be manually activated if they are spawned during runtime. This definitely makes it an easier task for the player to shoot the enemies. 





Comments

Popular posts from this blog

UI Polish

AI Navigation Problems - Yashwant Patel

Round End Cutscene Implementation