Array does not transfer information via game Instance

Hello everyone, I have a problem. I wanted to create a metod to spawn specified characters in another map. The characters are child of a PG_Ally/Enemy and this one child of a PG_Master. The CharacterSpawner use a varieble of the game instance to see which and how many characters spawn. When i try to set an array of PG_Master in the instance and access it in the same level it works fine, it spawns the right characters in the right position, but when i try to open an another level with the same blueprint for spawning the characters it doesn’t works. It’s like the information of the array it’s nullified. I Tried to clear the array of the game instance and then with a for each loop added the objects one by one, but it doesn’t works. I could not try a way to make it work. ( the game instance is set in the project settings ) there’s something i can do to fix it?





I see you unpacking everything from the GI, but I don’t see you putting all the information in?

You have to load it before changing levels, it doesn’t load itself :slight_smile:

I don’t understand, it needs to be load? i put all the information in the first image, first i clear the array in the GI then i add one by one the objects. After that i open the new level and it should work as in the same level, because the spawn characters use still the information from the game instance. I need to load it after putting it in? i used few times so maybe i’m forgetting something.

Saving object reference to a Character won’t prevent it from being destroyed when changing level. You need to save a class reference or whatever data is required to respawn the character in the new level instead.

Yes, like @GarnerP57 says, after you’ve changed level, the actor references are no longer valid. You need to save the actual information… :slight_smile:

thanks! now it spawns them, but now i have another problem connected. If i try to change the values of the character in the first level and then open the second it spawns them with no modification but with the first one that i set in the bp

how do i set the class default variables?

I was thinking about setting them after. the problem is that the modification would be different for every character and they could be not the same one every time, so if i set the variables with a switch enum ( with the role ) on the spawner should be fine. But how do i set different variables in the IG knowing that should be added only on a pg and no other?

if i create a float variable “Buff” in the GI and set it in the first level, it would work only if i have 1 character, otherwise it would sett all the pg as the same buff, so i must create an array of buffs for every character and the check if the role is the same one as the buff and the set it.
Is there a way to set the Class defaults? because i think it would be cleaner and easier.

If players got a buff they didn’t have before, you have to save that on a player by player basis.

If it’s part of the default setup, you can pick it up with ‘get class defaults’.

i’m searching on how set the player basis but i cannot find it. i found this in the unreal documentation but i cannot understand

in the image that i sent i tried to set a variables adding for testing to a float variables, but in the other level it doesn’t appear to do nothing.

how do i save the basis? i know how to get the defaults but i have no idea on how to set it. I’m using blueprints i don’t know if it’s managable with them. Also I’m using unreal 4,27.2.

In the blueprint class, you set the variable. Then it will have that value for all instances of that class, unless you change it.

You can find those values, using ‘get class defaults’

image

ohh ok, so instead of spawning them and change them after or before, i change the bp of the characters individually. So i cast to them change the variables and then when spawned should be with the buffs. I get it right?

Nope, I don’t think you’ve quite got it… :slight_smile:

When you make a character BP, it can contain a float ( health ). Set it to 100.

Every character you spawn of that type will have health 100.

BUT, if during the game, they get a health buff, and go up to 200. You don’t change the BP, do you? You have to keep a record that one of the players has 200 health.

In the next level, you spawn this player, and set the health to 200.

It’s because of things like this, we use the save game

Thanks a lot! now i understand more about it should works. So i’ll try to create a stats save, but i need to create variables for every characters that should be buff, but it shouldn’t be a problem. Anyway thanks again, it helped me a lot!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.