Storing data for actors

i’m trying to set it up so when a collectable is collected, it stores a varible so if the player goes to the same level, picking up the collectable that they already got wont add to the counter, how can i store a collected variable because i want it to save to itself and not duplicate of itself. more to say, i want a actor to keep its value so if the level is unloaded then loaded again, the value doesn’t go back to default

Hello !
I think you should read a bit about gamestate and game instance :

But mostly about game Instance if you work on a solo game.

i have tried that but i want it to save in the same level, or if i cant, to save it to sepreate actors, even if theres more in another level, because i dont want it to when you get the first collectable, i dont want the first collectable in another level to be collected

I don’t get what you want to do exactly but I insist, Game Instance is what you want.

for each of your collectable, you create a variable in the game Instance and assign a boolean value (or anything else…)
When you load your level or restart a level, you just have to check this value to know if this collectible must appear or not.

You can build the name of the collectible variable in a way it’s clear to you :
name_level_number : collec_01_01, collec_01_02, collec_03_01

The first collectable of the first level is named collec_01_01 and the first collectible of the third level is named collec_03_01 in your GI… There’s no way they can be confused.
You can also store arrays inside a game instance if you prefer this way… {collect_level_01}, {collect_level_02}, … This way, you can use forEach loop and array index to access each collectible variable.

The game Instance can be updated and read inside a level.
You can access the Game Instance from any BP (levelBP, actors, custom…) and you can then put your read/write mechanic inside your level or inside each of your collectible.

If you really can’t do what you want with this, then, I misunderstand what you want and you need to reformulate it, pointing exactly what you can’t do with GI.
Be brave :slight_smile:

the problem is getting the right actors to each varible, they all would check and assign the same varible, thats the problem

You’ll have to set in your actor witch variable check in the GI…
Maybe do you need to read some tutos about variables and communication between BP :slight_smile:
From here, you have a hole in your knowledge.

You can set a specific name for each of your collectible and check a unique variable, build from this unique name.
In your GI, you’ll have as many variable as you have actor. One unique variable per unique collectible.
Each collectible check his own variable, no conflict.

i’m trying to say 1 actor placed multiple times in 1 map but each with its own varible to tell thats its collected so then i can set a system to have locked levels so they cant cheat

Ok… That’s what I say.
You can’t save a runtime modified variable inside an actor. Every object of your game is reset at level start (to make it short…)
There is only one place in UE4 where the variable are wrote on disk and can be read, it’s the Game Instance.
So, you have to store what you want inside this object (GI) and read it from where you need it (your actor).

Let’s do it !

First, you have to create your GI and set your project to use it.
Inside your nex GI, create an array of boolean named “collectibleList”
If a collectible has been collected, the boolean value of his index in the array will be set to TRUE and if not, the boolean value will be set to FALSE.

demoGI_01.png

Now, create your collectible BP.
Inside your collectible_BP, create an integer variable called “unique_ID”.
Make it editable and eventually, editable at spawn if you need it.
This variable will contain an integer, unique per collectible, that we can use to get the state of the collectible in the GI array (by use it as index of array item…)

We can now build a read and a write function in the collectible.
As you can see, these functions use the unique_ID to read or write the array.
If you try to check the array at an index that doesn’t exist, it will return false (the collectible has not been collected yet).
While writing, don’t forget to check the 'size to fit" box. It will then create a new index if the wanted one doesn’t exist yet :wink:

When you put your collectible items in your level, you’ll have to manually set the unique_ID variable to make sure each of your collectible has his own unique ID.
If several object share the same ID, they will also share their collected state…

I can’t help you more without doing it for you and I don’t think it’s the purpose of this forum :slight_smile:
It’s one way to do it. I can easily imagine several other ones.
I didn’t test my code, there maybe an error in it but I’m pretty sure about me ^^.

f23d3c21452852e98a0717ffab7676415646c0a2.jpeg

PS : If you want to have several save game, you can read about the save game object. I understand it as some sort of instantiated Game Instance…

FINALLY it works

The “finally” is certainly a bit too much :slight_smile:

well the fact that i can now add locked levels makes the collectables useful now