Score system with multiple character blueprints

I’ve tried a bunch of tutorials and forums, but after hours of trying I figured I’ll try posting here. I’m trying to make a game where you switch between two characters with different inputs and meshes, and have made a BaseCharacter with the two child characters. I want to make a score system that register when my character overlaps my BP_Collectible item, and manage this fine with one character. However I’m struggling to make this when I have two characters I switch between.

(Blueprint of the character switch set up in each of the child blueprints, calling the other opposite to change into)

Currently my character actors are set up to be destroyed when they switch, as this seem like the easiest. (I’m not that experienced with coding). I’ve read that I can store scores and such in player state, but I can’t figure out how to connect the overlapping collision to register between the collectible and the character- how can I store my variable so it adds the total character score even though my actors get destroyed?

(Blueprint of current score system set in the BaseCharacter. It only works with one character, and resets when actor is destroyed/changed.)

Let’s see if I understand, you have 2 characters and you can switch between them by pressing a key (destroy one and the other one appears in the same place), also you have collectible items that get destroyed when you overlap them and add points to your score (score individual per character) righ?

  1. That branch node is unnecessary since you have it set to always be true.
  2. You need to store your score system somewhere that won’t be destroyed when you create a new player character instance so a player controller or player state (mainly for multiplayer)
  3. I would reverse your setup so have the collectible check if it overlapped the base player character not the character checking if it overlapped the collectible. Then cast to player base class, if that is true cast to your player controller and update the point value. A controller will remain even after you switch.

If you need help with casting, references or setting up a scoring system you can check out the videos in the following playlist. I go over similar systems in more detail

Yes, that is correct.
The points to the score is set in the parented character, not each character right now. But since the actor gets destroyed so does the data of the score, so it deletes that information regardless of it being in the parented blueprint.

Okay, thank you. I’ll try around with that then.
Sounds like it makes sense, now I just gotta figure out exactly how to do it :slight_smile:

I’m struggling to understand how I cast and connect this to a variable from a different blueprint

I go over how to cast and the references needed in video 1 and 25. Were you still confused after that explanation?

I had some problem accessing the variable from player state- i couldn’t get a correct object reference? - but i got it working by storing the variable in custom game instance, and casting with get game instance as object. Seems to be working now atleast.

I made this in the BP_Collectible, and store the Score reference in Game Instance.

I’m having a different issue I was wondering if you could give insight on?
I tried to follow your score system tutorial (Unreal Engine 4 Tutorial: Scoring System and Function Inputs - YouTube), but can’t get the HUD updated to the score.
I think the problem is that I can’t get a reference to the blueprint widget, so I can’t pull the Add score function. In your video you take a reference from your ThirdPersonCharacter, but I don’t have a cast with the same reference, and would it be possible to do a cast to the blueprint itself? In that case I would also need a object reference, what would this be?

Can you post some screen shots of your setup? Especially where you create the widget, where you are storing the score and how you are trying to pass the score data to the widget.

I make the widget in the Level Blueprint. One simple widget.

Event Graph in HUD blueprint. (Must say I’m not entirely sure how this connects things, but it should be the same setup as in the video, just switched out character with game instance)

Add Score function in HUD blueprint

Here is the score system/destruction of the collectible item in my BP_Collectible.
I assume the cast to CustomGameInstance could be switched out or used to get the proper reference to the HUD blueprint? ‘Score’ variable is stored in my Game Instance blueprint.

Might be some other fluxed up stuff in there, so I appreciate any notices. Spending a lot of hours trying to understand these things. Found some of your videoes very helpful!

I see, your issue is you made the widget in the level blueprint. That is a bad place to create the widget because it is notoriously difficult to access in situations exactly like this one. You would need to use an event dispatcher and have a reference to your player character within the level BP and through that have an event dispatcher from the character tied into the level BP to call the function to update the score in the widget. It is a very, very round about way to do things because of the difficulty of accessing the level BP. An easier method is to create the widget in something easy to access like the player controller, player character, an object in the world that handles all widgets etc. These will be easy to reference and with that reference you can access the widget. If you watch video #25 around the 14:25 mark I explain this method of widget creation and how to access it from other blueprints.

I tried to make the widget in a GameManager blueprint in the world first, but it wouldn’t seem to work. I tried placing it in the level blueprint, and then it did work, so I couldn’t understand the difference of why it isn’t working? I have the exact same setup in a blueprint as I had shown in the level blueprint. Is there something else different I have to do?

Show me how you tried it in a GameManager blueprint. How did you reference the GameManager BP? See you never referenced the level BP because you didn’t go through that long tedious process with event dispatchers I described above, so I am curious when you say you did what you did in the level BP and it “didn’t work” what did you do? You need to make the GameManager, create the widget, store it as a reference variable within itself, drag it into the world, reference the manager BP using a “get all actors of class” or other such method I show in my video on references, then access the widget variable reference through the reference of the game manager BP. Post screen shots of the game manager setup that wasn’t working if that didn’t make sense.

Well won’t you look at that. That made it work indeed. Thanks so much for the assistance! Good job on them videoes, I’ll try to look them all over.

Resulting blueprint in the BP_Collectible referencing the Create Widget in my Game Manager BP.

Hm. After further working, I now tried to make another level and connect the two with open level in the level blueprint.
When my character enters the trigger box and opens the new level, the score seems to be multiplied. Do you have any immediate thoughts as to why this is?

I haven’t made any save or load system to the score yet, and assume this could fix this problem when opening new levels. Am I correct about that assumption? If so, I’ll make that soon.

Not sure about the multiplied score. Would need to see screen shots of how you set that up