Adding int counts from BP to viewport not quite working - Updated 01-11-16

I think I’m off on my blueprint scripting somewhere, or maybe it’s just badly placed.

I followed this video series and a few articles from here, for what you see below.

I have a text area in my MainHUD BP for my death counts in the viewport, which I bound to a function.

After that, I pulled in a int + int from death count var (The corrected script) on to my spike mesh which I’ve cut into my death handling script. At this point when I hit my mesh, nothing happens in the Death Count text area.
However if I use the “incorrectly wired” BP (int + int from death count var link) it kind of works, the first hit does not register, but the 2nd hit onwards works, but it does throw errors after I stop the game.

Also, after the death and command line restart level, the death count does not stick, it resets back to blank (0).

Where am I going wrong at here?

I’m probably just overthinking it, once again, and it’s something simple that I’m leaving out.

You can all these images plus a couple of more here: Let it be the beatles download mp3 - Album on Imgur

Well the answer is in your pictures or rather in your setup.

To display that number you “Get Player Character” and then via the interface get the number of deaths.

This means you need to implement a function to return this number implemented in your player character and have to count that inside of your player character.

The reason it doesn’t work is because you try to modify the variable before you have casted the “Other Actor” to your character. This means you can not access those variables when this script is called the first time and it won’t work for every other instance of this blueprint the first time you use it either.

Put the “Cast To SideScrolelrCharacter” in front of “Set Death Count Int Var” and it will work the first time and not throw errors anymore. At least not related to that.

“Restart Level” does essentially the same as “Open Level (current Level)”. This means it loads it new and everything saved in any variable inside of the blueprints in that level, inside of your character BP, inside of your controller and inside of the gamemode will be reset to their default value. To save variables beyond a level you have two real options.

  1. Use a savegame. A savegame object is an object you create, add a bunch of variables and can then load or safe whenever needed. Every time you load it, the stored variables will be accessible so for example if you update the number inside of a savegame object and not inside of your character you will always have the correct number displayed. Docs for savegame objects and how to use them in BP and C++

  2. (and this is preferable). Use a Player State. A Player State will be taken with you from level to level. You will have to create a new Player State object (just like any other class just don’t select “Actor”, or “Character” but use the dropdown and search for “Player State” when creating the (Blueprint) Class). Make sure you set that class as Player State in your Game Mode and use it via Get Player Pawn > Get Player State > Cast to your Player State. From here on out it’s the same as using the Savegame. Just get the variables or set them. No need to save in this case they will be saved automatically… just not beyond closing the game. Only through level transitions.

Okay. Let me work on this and I’ll get back. It might be a day or two. I’ll update if I have any other issues or if I get it done. Thank You :slight_smile:

I’m still working on this. Running into some issues with a save game tutorial I’m watching and following. I’m going to try to work it out myself before asking for help on it.

Okay I took 1 or 2 day break and came back to it. I deleted just about everything I did the other day because I have no idea what was what. I even deleted older variables that were in use, death count, and decided to start from scratch once again.

In the SaveGame blueprint, I added a Int variable for PlayerDeathCount. Is there anything else that I need to check on the right for me to be able to call this to/from other blueprints?

  • For saving map/level names, so they can be called when a game is loaded. When I create a variable in the SaveGame blueprint, what variable type should I choose for my level names?

For example, my level names are Level01VeryEasy. Would I choose “Name”, “String”, “Text” or something else?

Each level is slightly different, with different ways for the player to be killed, but they all use the same few meshes. Should I be calling the Death function from the damaging mesh or from the level blueprint or character blueprint?

I did create a enum for all my level names, mainly made it so I can remember what I named the levels. Some are probably temporary names, but I might keep it in there for Easter Eggs. I watched some video, don’t remember it now, where they used a Enum for the levels, but they didn’t go into how to set it up to use it in blueprints… probably should leave this out, but maybe it’ll help in some way.

If this sounds like garbage, forgive me, I’m having issues trying to say what I’m trying to, while trying to recall what I can about all of this. I think I’m just overexerting myself over something that is probably simple. :expressionless:


Edit:

I followed this Q&A, and this is what I currently have for saving the variables, I think.

I’m almost done with dealing with this. After nearly a month, I still can’t get anything to work. I’ve watched and read tutorials, YouTube and official documents.

I’ve restarted this from the beginning with nothing and worked up from the official documents and YouTube channel, the suggestions here and other threads. Nothing.

Seriously, why in the **** is it so hard for me to call a variable from one BP to another. That Target stuff is apparently over my head and I’m just to dumb to understand it.

Even trying to do what I did in the images from the first post, I can’t get it to work anymore.

I stopped working on the save game feature and just deal with trying to get the death count to show back up on screen. Nothing.

You would think after dozens of videos and UE4 answers threads, I’d have this working, but nope.


What am I doing wrong? I know its possible, as thousands of others have done this successfully, why not me?

I’m so confused on everything now, and it’s putting me off from actually wanting to do anything in UE4, which is not what I want to happen.

This is what I have, I have no idea if it’s everything that is actually needed.

http://i.imgur.com/kxEV0Iz.png (DeathCountGUI variable apparently nothing, which is why it’s not public)


I went stupid there, I got it partially working. I forgot that I had to create the widget for the MainGUI for the DeathCount.

Now, my issue is that my DeathCount does not increase when needed. It stays at zero on the UMG text area.

Updated BP https://i.imgur.com/zfKHUoa.png … nothing else was changed from the previous images, other than what you see on the updated image.

Adding a Print String on to the Set variable output, it shows it’s added + 1, but doesn’t add anything past 1, nor does it show on UMG, just in the print string.

Please close this.

I figured it out, with help from another person elsewhere.

It was my “Other Actor” when I promoted to Variable I didn’t “set” it.

Thank You everyone who helped me before :slight_smile: