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
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âŚ
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â
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âŚ
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!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.