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"

Is there a way to make a coin save that it had been collected?

And when I restart a level, then it wouldn't appear?

Product Version: UE 4.16
Tags:
more ▼

asked Jul 31 '17 at 11:58 PM in Blueprint Scripting

avatar image

Rycer76
12 2 3 6

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

2 answers: sort voted first

Yes there is. You can use Game Instance. Part of the Game Framework. Game Instance is persistent throughout the game. Increment a variable there and get it at anytime when you need it. If you don't want to use GI, you can use Save Game.

https://wiki.unrealengine.com/Game_Instance,_Custom_Game_Instance_For_Inter-Level_Persistent_Data_Storage

https://www.youtube.com/watch?v=5w594D3qtLs

https://docs.unrealengine.com/latest/INT/Gameplay/SaveGame/

https://www.youtube.com/watch?v=6La5HrLf1j4

more ▼

answered Aug 01 '17 at 04:04 AM

avatar image

VictorBurgos
2.4k 61 27 113

avatar image Rycer76 Aug 03 '17 at 01:09 AM

But how to use it? These videos don't really tell anything useful for me. Let's say we have 60 coins on the map. When we collect them, they will be added to our sum of coins, but they won't appear on the map anymore.

avatar image DonBusso Aug 03 '17 at 01:59 PM

Destroy the coin actor if you don't want it to appear on the map anymore.

avatar image Rycer76 Aug 03 '17 at 07:53 PM

Even after restarting the level?

avatar image VictorBurgos Aug 03 '17 at 08:17 PM

Well, there's a lot of ways to do this. But if you simply just destroy an actor, on level restart, it will typically appear again (depends on how you are doing it). But, what's easier to do, is just have a bool. bCollected. When picked up, have this particular referenced actor set bCollected. Then on Level Load, check to see if any actor has been collected already or not. The thing about this is... simple Open Level or Restart Game, will reset all these values. So, you will need somewhere persistent to keep track of this. Either a SAVEGAME or Game Instance is your choice. This requires you to have references for each of these actors however.

avatar image Rycer76 Aug 03 '17 at 08:47 PM

Wow. That was easier than I thought. Thank You!

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

Create a Blueprint Class extended from GameInstance. There add a variable to your collected coins (GameInstance remains even if you change levels) On the actor that fires the event when the coin is grabbed (probably your character), add a GetGameInstance and cast it to your custom GameInstance to access the variable you just created and set it to its current value plus one.

Every time you need to access that variable you will need to cast to your GameInstance class, if the casting has to be done many times, then you might want to do the casting in the BeginPlay event and store the GameInstance reference to use later.

alt text alt text

If you want the value to remain after exiting the game, it has to be done with the SaveGame class, explained here is the setup of how to save and load a variable with the SaveGame class > https://docs.unrealengine.com/latest/INT/Gameplay/SaveGame/Blueprints/index.html

more ▼

answered Aug 03 '17 at 08:37 PM

avatar image

xeoncat
91 1 5 10

avatar image VictorBurgos Aug 03 '17 at 08:43 PM

Sounds exactly what we've been talking about... /shrug

avatar image xeoncat Aug 03 '17 at 08:48 PM

I may have misunderstood the question then

avatar image Rycer76 Aug 03 '17 at 08:49 PM

Thank you anyway.

(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