Download

passing inventory into a level

So my game allows players to choose equipment before entering the main game, so I have a level that fires that equipment GUI and lets the players choose their stuff… they click play and they no-longer have their stuff…

How can I transfer the inventory from the equip screen / level to the game level ???

W-Jones

Either using the game instance or the save game.

You have to store the choices, and then pick them up from the new character when the level starts.

So I have a save game object and I have added my inventory component to it.

I create a new save_game object “My_Save” and “set” its inventory component to be equal to the inventory chosen and set a test variable from “My_Save” to a “A test” and I “save slot”

When I load that save, and cast the returned object to My_Save the test variable is set, but the inventory component is empty.

What am I doing wrong ???

W_Jones

Here are the basic rules of save games:

Are you doing it like this?

ClockworkOcean - Thanks but I have that working… for basic variables, just not containers. Do they need to be handled differently ?

When you say ‘container’ do you mean structure or…?

( PS: Use the quote button, then I get a notification )

Sorry I mean component… My inventory is a component… which its self is an array of containers, containers are an array of item objects.

W-Jones

When you say “Item Object” do you mean Object Reference? If so, you’ll want to create a string reference and use that instead.

X object = “somestring” → store in game instance … On spawn convert string to object via spawning said item etc etc.

Like @Rev0verDrive says, it’s not good to store object references.

It’s a little hard to explain clearly, but it will trip you up in the end.

It’s better to store generic types if you can. For instance, if it’s an array of ‘things’, you can use integers ( or strings ) to represent the things.

For multiplayer (packet size) reasons I use string instead of int.

Not sure I understand - Item Object is an Object, container is a struct that contains an array of Item’s (plus thing like the containers name, No. slots etc).

An object reference is a pointer to an object - correct ?

I am not storing pointers to my objects, I am storing the objects themselves (or at least I think I am), do I still need to convert everything to a string ???

W_Jones

You can’t store the objects themselves. That’s why you need to store an int or string.

When you read it back out of the save game, then you can spawn the correct items, depending on what’s in the slots. It looks to the player like they stored objects, but you only ever stored an ID of the type of object.

OK I get the idea :smiley:

When you load the new level the object references are no longer valid. Said actors no longer exist. Thus you need to store an int/string reference for them. Then spawn them in the new level -> valid object reference.