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)
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.
Try a “Get Player Character”, “Cast To” your character class and use the result as target for your “Get Gamescore”.
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”.
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