[INFO DUMP: BP_Interactable / BP_Spawner]
Wow, shortly after I have made the last post, so many things broke and I have spent a lot of time to figure out what has happened and when. That’s what you get when you are too excited to learn things and implement them while you forget to mąkę it a habit to test the whole game. Afterwards, it’s difficult to find the cause, even with the GIT version control system set up (Blueprints are sadly just files so you have to fix things based on your memory, which is not always good).
1. Improvements to the BP_Spawner
When I have been tweaking the MainMenu Level I have noticed that in some cases not all Resource Node Types will spawn, and even if they do, the Foliage would be still missing. After quite a bit of thinking what ended up to be the issue was that I have introduced the Get Random Reachable Point in Radius nodes. Because of them, if things spawn at the Centre, no point in radius can be reached altogether and everything will appeal at 0, 0 location.
I could have reverted the logic but then I thought to myself: why not to fix it instead in a way where that part cannot be changed - and so I did.
As the first part of this multiple-step process (more in sections 2 to 3) I had to create an array of distances measured from the Origin Point of the Spawn Marker (which we create with each cone that forms the island) to the Spawn Point of the Interactable to be placed within the said come. As a side note, get into the habit of clearing the array, otherwise old entries will be stored, making it unreliable, and forcing you to scratch your head in wonder, like I did.
Minor digression:
I decided to implement the Delay between spawning the Resource Node Types since Island gets dynamically checked with each group spawn. This way at least the Resource Nodes are more likely to not get spawned at the same time - far from ideal, as it all takes time still.
Improvement in the making:
- To implement a macro that would grab the number of Resource Nodes of a given type that survived being destroyed and feed that Information into the Delay so that the moment the last Interactable of its type spawns (with animation time included), the next spawn type jumps in.
2. BP_Interactable’s Event Graph Tidy Up
Once the BP_Spawner’s changes have been finally done, it was time for the BP_Interactable side of things. And when I looked at it (you can see its state in the previous posts), it was a mess and needed tiding up. Results for the lift up below:
I was heavily relying on the BP_Spawner to preparae information for me, so I have put all the logic into the Collapsed Graph. That area was constantly growing, and including now the Distance From Origin Array, which I have implemented recently, morę things were likely to come, making it obvious to visually separate things.
2.5. Object Name To Index Macro
Not really tidting up but worth mentioning it here before the next big section. It occured to me that the Interactables are being destroyed at many stages so finding their distance from origin inside the array (to feed it on later) felt a bit problematic, but it turned out simpler than I thought, thanks to the ClockworkOcean’s post (What's the best way to remove letters and special characters from a string? - #3 by andbc), as I knew how I wanted to approach it, just needed to find the right pieces to built it from. And, as it proved to be a useful function, I have elevated it into the Macro, allowing me to use it freely in the current project and later ones if need be (I preferuje putting those in a separate Macro Library father than inside the Blueprint).
3. BP_Interactable’s Overlap Checks
Now came the time to fix all the spaghetti flow inside the Validation Part of the BP_Interactable, and as a result it is less of a mess, I hope. We will see when I look back at it in a month or so.
After moving and improving things around, the checks that I needed so far ended up to be as follows:
- Interactable is not in the PlacementMode (is not a building/crop type, so we don’t destroy the said Interactables when we place things fon the Island by hand)
- Interactable is not overlapping with another Interactable, with Error Margin allowed (this still needs imrrovement as the extents of the Interactables vary so is not too optimal yet)
- Interactable is not colliding with the Town Hall (special case, as that’s the only building spawned before anything else)
- Interactable is not too close to the Origin Point (what we compare is our allowance against the Distance From Origin we have stored via the BP_Spawner - also, triple check the order of the pins for things like that as you might be thinking that all is in order but the things should be inverted, which took me a long time to figure out)
- Interactable is not spawned at the Centre Point (a.k.a does not match the Spawn Marker location - another not super obvious one as the BP_Spanwer uses Stepped Position Node, so you have to keep it in mind when doing positional checks on the Island)
Thanks to the above points the Interactables are able to remove themselves from the island when they end up where they shouldn’t be. Not ideal, as preferably I would like to, again, move them out of the way and put them somewhere else, which is something for later, fingers crossed not too late.
4. Navigation System
We did all the tiding up and added all the checks in the BP_Interactable and now we can proudly see how the Interatables spawn on the Island, right? Nope. Well, things did spawn but not in the way expected.
That was because of the Navigation System (Edit > Project Settings > Navigation System). Oh boy, that took me not only by surprise but also, since I had no idea what was happening, age to figure out and fix. Lucky for me I knew of the P button that shows your Nav Mesh and ultimately this post put a lot of light on how to resolve the issue: Why is the RecastNavMesh object not created for the Nav-Agent?
Basically, at one point in the project I have broken the Navigation System which resulted in the Interactables returning an incorrectly sized navigation blocker area, which prevented the Foliage to spawn due to lack of space. I still don’t exactly know how things are set up, especially for Villagers, but all I understand is that green is for Interactables, Orange is for AI. Also, AI doesn’t like extra tags on the Resource Nodes (job will fail to load), so I need to inventigate that as well.
Anyways, the most important values for the project as of now are:
- Agent Radius (offset limitting the edges of the Navigation System)
- Agent Weight (to make sure the Navigation System is on top of the Island).
5. BP_Interactable - Placement Mode
Crops and Buildings are their own types, though they inherit from the BP_Interactable, so the Placement Mode is being used only by them to prevent the removal and redundant grond blend from happening. It also grabs a list of meshes so then later its easier to trigger the building stages the game uses.
6. BP_Interactable - Building Progression Level
Not the best description by me as what this part of the blueprint does is to keep the time to finish placement of either the Crop or the Structure so that if we leave the game, the progress can be stored and all the right meshes are loaded based on their progression level (thus the Mesh list).
I think it could be improved but I’m not near enough the Crops and Building Blueprints yet, but, as always, it will happen eventually.