Blueprint - Both working and not working.

Hi anyone,

Could you throw some ideas at me as to why I might be getting an issue?

I have a “game” level with 2 arrays, one for player characters and one for AI characters. When I am in the Map level “game” and press play, the array of AI characters appear as expected and coded. However, if I run the game from the start menu and set up the player Etc, when I hit the button to move to the “game” level nothing appears.

So any thoughts on why the code works when I am in the game level in the editor, but doesn’t work when I am in the main menu when I run the game?

I have run through the code and it works in one instance and not the other, so the code seems sound there is just a difference between running it directly in level and getting to the level via the main menu.

Any thoughts let me know.

Additional info:

The AI array is stored in the game mode, of the level “game” that is all set up correctly and works. The team is designed and spawned on Event begin play.

The code to call the array and spawn the characters is in the level blueprint (because I needed access to the spawn locations which are physically placed in the level. I tried making a reference to them and then passing that through to another blueprint but it never worked, even when I was in the level (where it previously worked)

Genuinely any thoughts or ideas might put me on the right track so just throw them at me.

Thanks

There are 2 ways out of your current situation.

A) create a spawner manager based on an actor with an array variable that stores the spawn points (Make sure it have “Instanced Editable” checked). Expose the array to the editor (the eye symbol).

Once placed into the world you can now populate this array with the spawners inside of the level.

Then you can get the manager through get actor with tag (which you set) or get actor of class to get the manager and from that access the spawn points.

B) After begin play use GetAllActorsOfClass with the filter for spawn points and set the array in the game mode. (this will have the penalty that it will be calculated each time the level loads)

Thanks, I’ll take a look and see if it solves it.

EDIT

I had already done some of this already, just never hooked it up. I now have everything out of my level blueprint which is a relief.

However the problem still exists, the object has a spawn function which creates the actors at the spawn points, in the game mode I simply call that using the get actor of class, on the event begin play of the game mode. Again when in the level everything spawns fine, but doesn’t if I make my way to the level via the menu system. It’s so very odd!

So further info, I can see what is causing the issue but not why it is being caused. After a day of debugging I noticed that an Array filled with all game characters is being emptied when I go from one screen to another. Or should I say one level to another; the game instance should carry data across level loads though right?

When I play just the “game” level and don’t do any of the menu stuff the characters load and the array remains filled as expected.So something is going on between levels loading.

Okay if anyone come across this because they are having similar issues; in my case it was because I was creating objects on initialising of the game and storing them in an Array. When I swapped levels the garbage collector was deleting the actors I “spawned” as part of the code and was thus emptying my array when the next level loaded.

I knew objects within the level were destroyed when the level changed, but I thought because the data was stored in the instance the data would remain there. Unfortunately that is not the case, when they are deleted they are deleted from everywhere.

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