'Is Not Valid' but it seems to work?

hi,

  1. player overlaps coin
  2. the coin sets a variable on the player character BP
  3. updates the game mode variable
  4. game mode then saves it to the player save game

the overlap throws an error that ‘Is Not Valid’ but it seems to update it’s connected values properly so why throw the error?

seems to do both? valid and not valid

1 Like

How do you know that?

the overlap throws an error that ‘Is Not Valid’

What is the actual error message? Or do you mean the Print?


Does the coin actor get destroyed in this example?

1 Like

it saves to the leaderboard UI the correct values but yes it fires the print string on the Is Not Valid execution so i can it fails every time because it doesn’t destroy the object like it does if it was valid

1 Like

We can’t see that here - how do you update it? All the print string is saying here is that the Save Game data object does not exist. When do you create it?

When you say “it saves” here, what do you mean? Is there another saving system or you simply mean an UI widget update?

1 Like

the save game gets created at the level load

sorry for music forgot to pause, this shows the coins following the isvalid check to true at the same time invalid happens

oh wait maybe it isn’t updating it properly ughhhhhhhhhhhhhh

1 Like

What does the save game being invalid has to do with the UI update? Again, where do you update the UI? You say they are somehow connected, but we can’t see it here.


Regarding the SG being invalid:

Is this script in the Game Mode? Does it trigger? Because to me it looks like you do it in the Level Bluerpint… not in the Game Mode. So the the GM’s PlayerSaveGame var is simply invalid.

1 Like

sorry it appears it is broken, which in a way i guess is good

this is the coin pickup, it accesses the player save reference and checks its L1Coin value saved to it and if it’s bigger than the current coin variable amount in the player character

STEP 1 - character overlaps coin

STEP 2 - coin gets current value in the save game from the game mode ref (created when the level opens)

LEVEL BP

PLAYER SAVE BP

the logic is that the coin compares the characters current coin value they collected to the saved variable in the game save if the local is higher it saves it to the player save, replacing it with the higher score which gets represented (or is suppose to) on the leaderboard widget

1 Like

You create the the save game in the level blueprint and expect the game mode to know about it. It does not.

i’ve done something wrong i know that for sure because i have it setting the variable in the game mode as well? help i’m an idiot

1 Like

Nah. Create the save game in the Game Mode only, on Begin Play. And use that.


Atm, you create 2 separate save game objects. One in the Level, and one in the GM. Avoid using Level BP.

This whole thing can boil down to 2 BPs and a single integer variable:

  • the Game Mode - has a save game and updates the UI.

  • the Player - runs into coins and updates the Game Mode:

The coins do not need to know about any of this. Much cleaner, consider it.

1 Like

so should i scrap this from the level bp as well?

1 Like

I would. LB is good for stuff that is unique to this level only. If you have 1 level only in the entire game where there are coins to collect - you can use the LB for this. Other than that, avoid it.

1 Like

panicking now, its all such a mess suddenly

If you’re going to have LVL_2, or worse, lvl_3! would you like to create the very same script for EVERY level?


What you have does not belong to the LVL BP unless there is only 1 level in the entire game. And even then, I still would not do it. It also seems that we duplicate a lot of variables. This is not really necessary. Have a look at my example - the Game Mode does it all. And you can take it further, too:

  • the save game BP:

  • update the SG:

okay this is the coin BP

GAME MODE

GAME MODE ENDS HERE

Looks fine-ish… I just would not burden EVERY coin in the game with script - do the coins really need to know what the player is doing, what the save game is doing, what the game mode is doing? Why repeat the same script in 100s of actors… The coin’s job is to be collected, play sound, and get destroyed, not to handle save game communication:

That is all the coin should be doing here. But again, this is how I’d handle it - there’s more than 1 way, ofc. Make sure it makes sense to you.

1 Like

okay i’ve fixed it to the point the leaderboard and ui are representing the data correctly and all that but the leaderboard gets wiped on Open Level i think, and i only ever want it to wipe when the save game is deleted or change when a new higher number of coins is collected to replace the same game that was lower than a previous attempt

where do i move this logic to then if not on the coin?

As in my example, to the player BP.


However, if you want something more advanced and proper, I’d move the whole thing to the Game Mode, perhaps even the player does not need to know about any of this:

  • save game

  • coin:

  • game mode

The above translates to: whenever the player overlaps coins, we destroy the coin, increase a variable in the save game, and update the UI. The simpler it is now, the easier it will be to update later.

There is also the Game State and the Player State but if it’s single player, I would not bother.


Load the SG with the top score, and compare it to the current SG’s values.

Good luck!