Hey, on my ItemBP i have an integer value and on the game instance have a bool array.
Before playing game i set all the items id by hand like 0,1,2,3 and when player interacts with item i use set array elem to save the item been picked up and save it. On begin play it checks if the item is been picked up from game instance and if its it destroys the actor.
But as you can see the issue is giving integer values to items by hand. When there is hundreds of items its a really slow and boring way.
So how can i get random and unique ID for each item on the level and keep that ID.
Why does it need to be random? Whenever you spawn a new item, give it an ID++. When you save the game, save that one int, when loading, read it and carry on. It’s going to take a while before you run out of integers.
Sorry i write it wrong, the integer value is on the ItemBP and use of the integer is to check if the item been picked up or not from the array of bool in the game instance. So i need unique id for each item, it doesnt need to be random but when i searched for this problem i found answers like give each item random id so i write it like that.
If i made it like this how will any of the item will know which integer is his ID?
Here’s what I meant it more detail:
• spawn an Item, generate an ID++ → give an item their unique value identifier
• save: save items’ data and theirs identifers, also save the ID++ variable you used to generate unique item identifiers with
• load: load items’ data, load the ID generator
• keep generating new IDs as you spawn new items
Hope it makes sense.
That’s assuming you need an ID system in the first place as you may not - really depends on what we’re working with. You probably do since you’re digging into it.
Well i placed items on my level and trying to save if that item is picked up or not for the next time i start that level, if you know or think of a better or easier way to do it i would be glad to hear it.
Something to consider: in construction a GUID variable can be set if it is not valid and use that to id each instance. In save game a set container can store all guid that have been picked. Each actor instance only needs to check if its guid is in the set.
Note: copying actors in the world since they may copy the value of the original instance. Dont think it will work if items are dynamically spawned.
You can also use actor name + level name
as a unique ID.
Id do something like random int in range…insert that to a find or contains query on the array…if yes add if no loop back and generate a new number