When I try to attach the kill counter widget to event begin play logic instead of “on death” (like in the above character BP pic) I get massive errors:
I followed Matt Aspland’s tutorial for how to make an enemy kill counter. Issue is, I also have a proper “player death & respawn” system set up, and Matt’s tutorial doesn’t account for that. How do I get the kill counter to reset in sync with when my character gets destroyed and respawns?
I’m an extreme rookie, so I’d appreciate any advice be in ELI5 format… thanks!
So what that’s saying is “Accessed None trying to read property Char_REF.”
What that means is “Hey, you’re trying to access a variable here, but… you never set that variable so there’s nothing to reference in your Char_REF. It’s empty…”
So look around for a “Set Char_Ref” in your tutorial, it’s probably going to be on Begin_Play as it will be referencing a character of some kind and you need to set that after the game starts for it to reference something that exists dynamically in the level.
Hi @Mind-Brain , thanks for the reply. I added a photo to my post–I did set the character reference. The issue is, when the character dies in-game, this ref apparently ceases to function, even after the character respawns. That’s what my whole post is about–when my character dies, the kill counter function just implodes and the errors begin. So I’m wondering what I can do based on my existing setup.
when you respawn get the widget and update it with the new character ref, or put the kill count on something that doesnt get destroyed, like in your case the gamemode but you’ll still need to reset it anyway
probably the best idea is to move the respawn,score and widget all to the player controller that way everything is in one spot and wont be lost when the pawn is destroyed.
the widget can just bind to the score event on the controller if you know how otherwise just update it when you set the value
@Auran131 Admittedly, I’m having a hard time following your tips (I’m too rookie to understand how to implement some of the things you’ve suggested) but I think I made sense of some of the broader points and now I have this:
This setup works except on the initial spawn. But otherwise, with each respawn, the counter works, resets, etc. perfectly. Any idea how I can slightly modify it so it appears on the first spawn as well? I tried binding to “event begin play” in a ton of different ways, but all of them created character ref errors like in my original post. Not sure what event I could bind an initial instance of the widget to avoid errors.
so your saying respawn works but spawn doesnt? i dont see your spawn logic here?
technically spawn and respawn are the same thing so create a function that handles that to clean it up.
you only need to create the widget once, then just update it on respawn.
order matters so that refs are valid, on begin play create the widget save a ref, after that spawn and possess the character, when you spawn the character grab the widget ref and set the character ref in it, when you set the character ref update the score.
again unless you have a reason not too, move everything the the player controller, you’re still bouncing back to the gamemode so it could be your ref is on the gamemode when you want it on the player.