Blueprint function call in editor to prepopulate arrays


I have a blueprint function in an instance of my player character BP, placed in my level.
This function populates some arrays with data and can take many seconds.
I would rather do this in editor, so I set this function to “call in editor”:

  • I run the function then play in editor and it works perfectly

  • However, when I run the function and then package, the packaged game runs as if those arrays are empty.

Is there a way around this?

Many thanks!

You have not provided enough info. Some screenshots of function and where that function is called will be enough.

And if you have not called that function anywhere it will not work.

You have to put it in the construction script. I don’t think you can have functions there, but that’s cool, because you can either make it a custom event, or just put the actual code there.

Thanks for the reply, Atharva,
My intention is to never call this function in my code at run time, to save time when the packaged game loads.

In editor I click the “Meta setup” button (see 01.jpg) from by BP character (it populates arrays with info from 1000s of datasmith actors) I then play in editor and it uses that data to drive UI and functionality. All tested and working in editor 100%
What the function does exactly is not so important but is in 02.jpg if you are curious.
The simple fact is that the function works, but the data it creates only can be used when playing in editor.
So, when I click the “Meta setup” button and then package the game, the packaged game cant see that that arrayed data, so my UI is blank.

Thanks, ClockworkOcean,
In the construction script if I either:

  • run my function’s code directly (not as a function)
  • or run it as a function
    Wont this simply run every time the packaged game is loaded by the user? This will add to the load time which is what I am trying to avoid?

This will run every time you place the actor and when you spawn in actor. And yes this will increase load time.

If only there was an option to bake those arrays into the package! :confused:

Well, there’s no getting around having to make calculations for the setup.

Something else you can do, is make the calculations and put the results in the save game. At run time, all the BP has to do is load from the save game, no calculations.

It is possible to read/write the save game in editor mode.

Ah ha! Save game sounds like the perfect solution.
Thank you ClockworkOcean!

1 Like

Thanks again clockworkOcean, however I suspect a slight issue with how I am using the save game solution :frowning:

The data saved is a number of structs of arrays of level actors.
My UI is correctly built from this data (auto buttons named after specific actors), so that is all fine.

I need the buttons to toggle the “actor hidden in game” on their respective actors. In the BP it simply reads the current “actor hidden in game” state and inverts it.

The problem is, when I click the buttons nothing happens in game (play in editor), however when I stop playing in editor, then the corresponding actors hide/unhide as they should have in game.

See below:
e.g. Zone array struct contains ref to 4 actors, saved in editor via function (function called in editor).
I then loaded this data (within my Character BP) back into the original structs I made, here:

Here, the zone array struct is broken to access the actors within and toggle the “hidden in game” on the specific actor as per the clicked button (I use “bind event” which binds to my UI widget button)
The test print string does list all 4 actors every time I click a button:


Best to use the reply button, I only noticed this by chance!

I can see any screaming error, although debugging other people’s structs of arrays of structs isn’t easy.

My advice is heavy debugging code ( print, not debugger ). Are you happy the correct info is being saved and loaded?

Surely you use the same code to toggle viz whether you use the SG solution or not, what changed?

That sort of thing…

Sorry, I must have hit reply to topic rather than reply to your post!

I just figured it out!
All is now working with play in editor and playing the package too!

All I had to do was move the loading from “save game” in my Character BP from the event begin play to the construction script.
I guess using event begin play was too late for the UI to use the data

I think what was happening yesterday was that my UI was being created from the save game data loaded the last time I ran play in editor, so the UI all looked correct, but functionally it was trying to toggle visibilty of the actors that existed last time I played in editor.

Thanks again ClockworkOcean!!

1 Like