x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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) alt text

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.) alt text

Product Version: UE 4.21
Tags:
more ▼

asked Jun 01 '19 at 06:02 PM in Blueprint Scripting

avatar image

kajaarielle
3 1 2

avatar image ANTONIOPS Jun 01 '19 at 08:19 PM

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?

avatar image kajaarielle Jun 02 '19 at 09:39 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first
  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

https://www.youtube.com/playlist?list=PLyu-W38DvZhqByAoeva1jewB5s78zQHIy

more ▼

answered Jun 02 '19 at 04:56 AM

avatar image

Nebula Games Inc
5.4k 28 9 15

avatar image kajaarielle Jun 02 '19 at 09:41 AM

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 :)

avatar image kajaarielle Jun 02 '19 at 12:33 PM

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

avatar image Nebula Games Inc Jun 02 '19 at 12:52 PM

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

avatar image kajaarielle Jun 02 '19 at 01:03 PM

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. alt text

destroyandscore.png (106.2 kB)
avatar image kajaarielle Jun 02 '19 at 03:31 PM

I'm having a different issue I was wondering if you could give insight on? I tried to follow your score system tutorial (https://youtu.be/QGIie_bDmeQ), 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?

avatar image Nebula Games Inc Jun 02 '19 at 03:51 PM

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.

avatar image kajaarielle Jun 02 '19 at 04:17 PM

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

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) alt text

Add Score function in HUD blueprint alt text

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. alt text

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!

levelbpwidget.png (55.2 kB)
addscore.png (103.5 kB)
scorestorage.png (157.8 kB)
avatar image Nebula Games Inc Jun 02 '19 at 04:39 PM

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.

avatar image kajaarielle Jun 02 '19 at 05:19 PM

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?

avatar image Nebula Games Inc Jun 02 '19 at 05:31 PM

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.

avatar image kajaarielle Jun 02 '19 at 07:42 PM

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. alt text

avatar image kajaarielle Jun 04 '19 at 07:46 PM

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.

avatar image Nebula Games Inc Jun 04 '19 at 08:15 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question