Blueprints - Game score

I am trying to create a game score for my game so that when the player collects coins, it increments the score.

So far, I was able to get the score variable from MyCharacter blueprint in my coin blueprint, and to cast it back to My Character blueprint. However, when I try to do a print string from the MyCharacter blueprint upon contact with the coin, it doesn’t return the new set value.

However, it IS changed since if I try to do a print string from the MyCharacter it will show the new value.

Any help getting
-The print string to work in the coin blueprint
-Multiple coins working (it sets the value the first time, then it doesn’t work)

would be greatly appreciated

This sounds a lot like you only set the type of your “GameScoreGet” variable but could it be, that it’s still empty?

You could try two things.

  1. Try a “Get Player Character”, “Cast To” your character class and use the result as target for your “Get Gamescore”.
  2. Use the Hit result “Actor Other” if I recall correctly. One of those pins provides you with the actor which hit with the object. Use that one, again “Cast To” your character class and use that result as target for your “Get GameScore”.

I would suggest going with the second one :wink:

I am not sure to be understanding casting correctly. Do I have to cast IN the player blueprint or in the coin blueprint.

Also, whenever I tried dragging the game score get (the object variable I created in the coin blueprint), I have no options for casting (I write cast and no result show up)

Thank you very much for taking the time to answer

Ok just to make sure I understood everything correctly:

  • Your score is inside of your “Player Character” blueprint.
  • You have coin blueprints which should change this number.
  • Your Variable “TargetBlueprint” has never been “Set TargetBlueprint”.

The most simple fix would be “Set TargetBlueprint” right after your “Cast To MyCharacter”. That will take care of everything you wanted.

“Cast To” checks if the Actor / Object you provided belongs to the child class you check for.

“Event Hit” provides you with an “Actor” type. You use “Cast To MyCharacter” to check if whatever triggered the “Event Hit” was the child class “MyCharacter” from the parent “Actor” which you got.

Since you have no child class of “MyCharacter” and you already defined in your Variable that this variable is of the type “MyCharacter” it will not show any classes you could cast to since there are none.

But right now you only have an empty Variable of the Type “MyCharacter” and not actually your character. So you will first have to fill it (or do exactly what you did from the “Cast To MyCharacter” which you already did a bit earlier in your script).

Like that you will have YOUR character and it will change properly.

Edit: To be honest though I would suggest doing this a bit differently. It should be a lot easier creating a function inside of your “MyCharacter” class which does the adding of points. You just call it “Add Score”, make it provide a “Int” variable with the amount and simply call it right after your “Cast To MyCharacter” with the output “MyCharacter” pin from there.

You will also be able to call the same function later on from all types of things which should give you points :wink:

Sorry for getting back this late. This did solve my issue. Thank you very much for your explanation. You made my day :slight_smile:

Sorry for getting back this late. This did solve my issue. Thank you very much for your explanation. You made my day :slight_smile: