why is my blueprint not adding value?

So I have the exact same setup to count how many objects I create and that works great, but when I try do add up how many objects gets destroyed the INTvaraible won’t add it just repeat (print text) 1.

is this cause the objects destroy and therefore it won’t add?


Looks like that “NUMofDEADChar” variable is local to wherever that Blueprint is, meaning it will always be 1.

You need to store that variable on something that persists, not a local variable.

ok, but then I have to ask why dose this work?
Screen Shot 2015-04-05 at 19.57.19.png

And what do you recommend me to store the variable on?


I think you’re misunderstanding how your variables are working. I don’t know the details of your setup or any of the names of anything, so I’m going to keep this abstract and refer to your first picture as Blueprint A and the second one as Blueprint B.

The reason your tally is not working in your Blueprint A setup is pretty simple:
Say that you have three spawned instances of Blueprint A; and you want the tally variable to be 3 to reflect this. The problem is, although they’re of the same class, and the variable name is the same, the instances don’t share the same variable. They each have their own version of the variable NUMofDEADchar. When that part of the script runs in each of them, the variable goes from zero to one, as instructed. When the instance is destroyed, so is the variable. And when you spawn a new instance, it will spawn with a NUMofDEADchar value of 0, just like the others. The problem isn’t that the adding doesn’t work, it’s that you’ve built your system on the assumption that the instances will all share the same variable.

If you want this to work in the way I think you intended, you need to store that variable in a place that will persist, such as a PlayerController, GameInstance etc. The reason why your Blueprint B counts correctly is because the variable is stored in a place that persists.

awesome, I understand now why its not working, but being fairly new to this I can’t say I understand how to use the PlayerController or the GameINstance.
All Im trying to do is count how many of my objects hits the ground, maybe I can somehow find that using collied information… the search goes on :slight_smile:

thank you all for all the help


If you’re still having trouble with this, I can give you a quick example. I’m short on time at the moment, but I can help you out once I get off work.

that would be awesome, and thank you… Im new to most of this but eager to learn :))

Maybe its a better way altogether to solve this… my goal is to subtract the objects that die off the total objects created… :slight_smile:


Okay, so here’s a simple method for handling tallies.

For my example, we’re storing the tally integer variable in the PlayerController blueprint; you can store it in any Blueprint you want as long as it’s something that will exist throughout the entire game session without being destroyed. Depending on your purposes you might prefer to place this in your GameState or GameInstance BPs, but whichever you decide the process is the same. Anyway, start by making your tally variables and setting up custom events to increment them. For my example, I have an enemy spawner blueprint and an enemy blueprint; and I want to keep a tally of how many enemies have been spawned from the spawner and how many have been killed.


In the spawner BP, we use a simple cast to the PlayerController to remotely trigger the event we set up earlier. This will make our tally tick up by one, which is what we want.


In the enemy BP, we do pretty much the same thing, but we trigger the other custom event instead.


And that’s all there is to it! Your tally variables are all stored in one place for convenience, and avoids the problem you were having earlier. I hope this is helpful!

absolutely phenomenal, love it and THANK you so much. I hope to get better at this and help others like you helped me…


That’s great to hear! Good luck with your project and with learning UE.

I said to much to soon :))

If you don’t mind have another look at this :slight_smile:
So I did this:
Screen Shot 2015-04-08 at 21.24.04.png

and here is the BluePrint that has the Events:

So I get the “failed” message so I know it tries to do something, but it seems like its not triggering my SpawnEvent in the target BluePrint??
What are we getting from the “player controller”?


I think the issue is that your casting setup isn’t right. If you’ve never used casting before, here’s the official documentation on it. Basically, casting is a way of testing a whether a blueprint reference is of a certain class, and more importantly, it’s a way of accessing the properties of that blueprint “remotely”.

So there are two parts to this. I think this the part that may have been tripping you up.

  1. This is the input pin. You have to connect a BP reference to this, otherwise the cast node won’t function. If you just want to use the cast node as a test to see if a BP is or isn’t of a certain class, you can plug in any blueprint reference here. However, if you want to be able to access the properties and functions of the blueprint, then you have to attach something that definitely matches the class you’ve specified (in my example, “BP_PlayerController” and in your example “MyCar_TL”). If you attach something that doesn’t match, the cast will fail; which is what you were experiencing. You need to make sure that what you’re plugging into the cast is the thing you want to be controlling. I’m guessing that MyCar_TL isn’t assigned as your PlayerController, so the “Get Player Controller” node is grabbing the wrong thing for your purposes. If MyCar_TL is your pawn, then you can use “Get Player Pawn” instead for example.

  2. This is the pin in which you can perform actions acting as your casted node. You can drag off of this pin to get or set variables, change properties or trigger functions on behalf of the casted node.

So with all that said, the problem you were having was with the input part. You need to provide a reference to MyCar_TL if that’s what you’re using. The reason I recommended PlayerController, GameState and GameInstance is because it’s especially easy to get references to those; there are “get” nodes for each of them.

Let me know how you get on with this :slight_smile:

Thank you so very much its works like charm now :slight_smile:
And thank you for helping me, its very inspiring to have you guys out there helping us newbies :slight_smile: