Hi all,
I’m starting to branch out into unfamiliar territories, not that many of the existing territories have been overly familiar just yet, but I’m plugging away at Blueprint slowly…
So, I have a number of NPCs in my level. I wanted to make this an objective for the player, e.g. destroy all of the NPCs. As part of this I wish to get the number of NPCs in the level and then display it as a remaining/total on the HUD.
I have working code for getting the NPCs, e.g. the count. I have the HUD/display all sorted from other aspects of the game (e.g. ammo).
What I became aware of was that whilst I was initially dumping this into the Level Blueprint, I would then need to replicate all of that for each level. So I set out trying to find out how to have a “count” of the NPCs for the objective at a “higher” level so to speak, which could then just be set.
I’m not familiar at all with the GameMode/GameInstance/GameState stuff at all at this time, however based on a little reading online (and the docs) it seemed like GameState might be the best place to hold this information.
I have that all setup and the only part which doesn’t seem to be working is the calling of, or the receiving of the event dispatcher. The code gets the count and that’s fine, but even adding a simple print node to the receiving bound function just doesn’t produce anything, and at the same, I’m not getting any errors.
I have used the same approach between actors and the HUD and that all worked fine, so I can only assume there is a difference with regards to the GameState?
Not entirely sure how helpful these screenshots will be, but this is what I have…
In the HUD Blueprint;
From the GameState Blueprint;
As a quick summary of how its setup…
- I created a Blueprint class based on GameState, I set its parent to GameStateBase (a lot of my game didn’t work before I did this)
- Within the BP_GameState I use the EventConstruct node to call my custom event which returns the length of the array for the NPCs in the level, populates a struct named NPCObjective
- The OnNPCObjectiveChanged event dispatcher is then called
Within the HUD…
- I get a reference to the GameState and set a variable to reference it
- I create a binding to the OnNPCObjectiveChanged event
- I would then call my event UpdateNPCObjective which would update the text on the HUD
The last step currently has a Print node wedged into it to just test, and nothing is output. If I however pop another print statement out on the exec flow after the binding and just try to print out the values from the struct, I can see the numbers, so, the data is there, that part has worked, but for some reason the event dispatcher aspect doesn’t seem to be working.
I didn’t encounter this issue when I was communicating between just actors, so my gut feeling is that the GameState aspect of this is perhaps the focal point of my issue, but I don’t know.
Any help would be enormously appreciated
I wasn’t able to find a lot online, but I did encounter someone else who had posted a couple of years ago with a very similar sounding problem, sadly the responses trailed off and there was no solution given;