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"

Beating Hight Score

Hellow, i'd like to do high score blueprint which will remember last high score i had done in game. When i beat it, there will be saving new high score. Points will be adding when i destroy actor. I've got 5 types of actors but i want that they will be counting together at one place. I try do it at my once with help of video on YT, but it doesn't help me. When i hit an actor, it doesnt even count. Any idea how to solve my problem? Thank You for your patient! alt text alt text

Product Version: UE 4.8
Tags:
image4144.png (315.0 kB)
image4155.png (359.7 kB)
more ▼

asked Sep 16 '15 at 04:30 PM in Blueprint Scripting

avatar image

R4c1o
24 6 8 8

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

1 answer: sort voted first

I don't know how savegames work in Unreal, but I've noticed some problems with your setup:

  1. You currently don't ever create a savegame because the Condition "checking" whether you load or create a savegame is currently always true. You need to connect the Does Save Game Exist return value to the condition for this to work.

  2. When actually creating a savegame, you don't ever save it to the "Clicks" slot because the Save Game to Slot node is not connected.

  3. I'm not sure Event ActorOnClicked is ever going to fire. "Level2" sounds like you're writing your code in the Level Blueprint but Event ActorOnClicked only fires for the object on which you clicked. You'll probably have to move the entire Blueprint logic into your base Actor class.

Also, your code doesn't do what you want it to do.

The Sequence node followed by the Get Actor of Class nodes doesn't do anything except being a) very expensive (collecting all those actors) and (once everything is connected correctly) b) increasing your click value by 5 (once for each type of actor).

What you're probably trying to do is:

  • check whether the clicked actor is of type Blue/Green/Yellow/...

  • if this is successful, increase score by 1

The good news is if you move your code into the actor Blueprint on which you can click (point 3 above), only these actors will receive the click and when clicked will increase the score. You won't need the Sequence and pointless Get All Actors of Class nodes. (Pointless because you don't even use the return value.)

alt text

I've also noticed that what happens after loading/creating the Savegame is basically identical, so you can really simplify the code:

  • Plug both Set Saver nodes' output wire into the same Cast to Highscore node

  • Delete the other Cast to Highscore node and every node following it

alt text

more ▼

answered Sep 16 '15 at 05:33 PM

avatar image

erinacea
1.8k 69 28 114

avatar image R4c1o Sep 17 '15 at 01:26 PM

Ok, i have delete what You had marked on pictures, but i don't know what exacly i need to write in actors blueprint, can You tell me, or better show it on picture?

avatar image erinacea Sep 17 '15 at 10:48 PM

Do your color actors have a shared parent class (other than Actor)? If yes, you can move your entire logic (that you posted here, minus the unneeded ones you deleted) into that class.

Otherwise, your best bet is to create such a parent class. I or someone else can tell you how to do that, but for that we need to know what your color actors currently have as a parent. When hovering the mouse over your actor class in the Content Browser, what does the tooltip show as "Parent Class"?

avatar image R4c1o Sep 18 '15 at 05:51 AM

there are actors parent class. So i can't get it into their blueprint?

avatar image erinacea Sep 18 '15 at 10:48 AM

First, I'd really recommend reparenting your color actors because that has several advantages. (For example, if you want to check if a hit actor is one of your color actors, but don't care which color, you could check whether it's of the parent actor's type because they all have the same parent. Or to check whether there are any color actors left in the game, you could call Get All Actors of Class for the parent actor.)

Here's how you can reparent your actors:

  1. create a copy of your entire project directory! (as a backup just in case something goes wrong)

  2. Create new Blueprint class -> pick Actor as parent class

  3. Name it something that makes clear that it's the new parent actor (something like BaseColor or ColorParent or whatever)

  4. Save and compile the new class

  5. Open one of your color actors' Blueprint

  6. Click on File > Reparent Blueprint alt text

  7. Select your new actor in the menu

  8. Compile and save the actor

  9. Repeat steps 4-8 for all your other actors

Test your project. If everything went well, the game works just as it did before and you'll have no new errors or warnings.

avatar image erinacea Sep 18 '15 at 11:04 AM

Next, you want to be able to call your saving/loading code currently in the Level Blueprint. In 4.8 it's not possible to access the Level Blueprint directly, so we need to work around this by using a dispatcher.

In your new parent actor, add a new Event Dispatcher, give it a name, and compile the Blueprint. Then add the ActorOnClicked event and call the dispatcher you just created. Again, save and compile.

alt text

Open your Level Blueprint. Replace the current ActorOnClicked event with a new custom event. On BeginPlay, loop over all actors of the new parent class (this will collect all color actors!) and call Bind Event to (your new event dispatcher). Connect the red boxes of the Bind Event node and the custom event you created earlier. Save and compile.

alt text

Here are some tutorials on Event Dispatchers:

https://www.youtube.com/watch?v=s5pIrpI7py8&feature=youtu.be&t=1m55s

https://www.youtube.com/watch?v=k-MAALv3P-Y

What happens here is that the Level Blueprint registers to the dispatcher, so any time the dispatcher is called, the Level Blueprint will hear the call and react to it. Now, whenever you click on one of your actors, the actor will call the dispatcher, which will inform the Level Blueprint to increase the score.

At least in theory. There are probably still some problems but I'm sure we can get this to work. :)

avatar image R4c1o Sep 18 '15 at 03:33 PM

ok i do all as you say in first comment, but now when i reparent actors, no one spawn in my game :/ i fix it, actors spawn, but they cant be destroyed in game. i try to do that, but if i cant, i will write :)

avatar image R4c1o Sep 18 '15 at 04:45 PM

When and where i need to create a custom event called IncreaseScore? I dont have it for now

avatar image erinacea Sep 18 '15 at 07:22 PM

You can call it whatever you want. It's just something to replace the OnActorClicked event in the Level Blueprint.

avatar image R4c1o Sep 19 '15 at 07:29 AM

and this blueprint which is saing my highscore i must put into new actor blueprint? And delete from level blueprint? alt text alt text

image4144.png (268.7 kB)
image4155.png (308.8 kB)
avatar image erinacea Sep 19 '15 at 09:36 AM

Ah no, sorry. I'll try to explain better.

In your the Level Blueprint (Level2, first screenshot):

  • replace ActorOnClicked with a BeginPlay event. (If you already use BeginPlay in your EventGraph, just connect the Get Actor of Class node after the current BeginPlay logic.)

  • link the Increase Score event to the Does Savegame Exist node. (You can remove the Print String node, that was just for testing.)

In ColorBP (new parent actor, second screenshot):

  • remove the connection between Call Dispatcher1 and Does Save Game Exist.

I hope that's clearer now. :)

avatar image R4c1o Sep 19 '15 at 09:53 AM

ok i do it as you say, but it do nothing in the game, actors are spawning i can destroy them, but i still haven't got any counting, and saving highscore. What is wrong?

avatar image R4c1o Sep 20 '15 at 11:55 AM

I think the dispatcher isn't working correctly, because when hit an actor nothing is wrinting in game, even is there a print string with some words. But all color actors are now in dispatcher parent class, and i don't know why it is still doesn't work.

avatar image erinacea Sep 20 '15 at 07:11 PM

I tested the dispatcher in a test project and I got my testing message (Print node in the Level Blueprint) printed when I clicked on my test actor (child actor of the one containing the Dispatcher). So it really should work...

Do your child Color Actors' Blueprints also contain an ActorOnClicked event? If yes, you need to remove it (or at least the first wire).

In ColorBP, if you place a Print String node between the ActorOnClicked event and the Call Dispatcher node, does that message get printed?

avatar image R4c1o Sep 21 '15 at 03:42 PM

i've got another idea how to do it work i want. In this idea i need to compare two dynamic materials, and for that reason i make another question in which one you try to help me :) and i make it that way: - in game are spawning random actors with one of 5 colors. It's one actor now, not 5 like it was before. - Now i need to compare these dynamic metarials. - When it will work i start to making a HighScore system, but with one actor clicking, not five, so Dispatchers are not needed now. - But I still don't know how i can do this simple HighScore, which will remember my highest score, and when i will beat it, the new one is saving. Can you help me with this things? Thank you very much for previous aid, it really helped me a lot and a lot to me:)

Sorry for my bad english

(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