I don’t think you should rely on that. Even if you could find that in the current version it’s consistent, this behavior isn’t stated anywhere, so it could change between engine versions anyways.
How exactly does Get All Actors Of Class grabs the actors into array? Does it provides same result each time? For instance I have three objects on the map and I fire Get All Actors Of Class, will it return array with them in the same single order each time? Can I be sure that Actor_01 will always be in third position in the resulting array, as long as the amount of objects on the level doesn’t change?
Well in that case, even if for some reason the order could be relied on, you wouldn’t be able to change the level at all. I don’t know your game, but is it realistic that a saved level will be the same forever and ever?
I never tried to save data for existing actors on the level, but a secure way I can think of is to save the data for the
Object Name instead of an integer, on load build a
TMap of all
actor name -> actor pairs, and then find the correct actor to be updated using its name in the map. It might be a bit slower than indices, of course, but at least this solution does not depend on the consistency of
GetAllActoryOfClass, and also doesn’t break if you want to edit the level, adding new actors, etc.
Or you could have a base actor for all your actors, in which you can generate IDs with
Editor Utility Widgets.
Someone with more experience might jump in with a better solution, but these are the paths I can think of.
Hey, looks like BlUtility is nearly exactly the thing I want. I was searching for the way to use GetAllActorsOfClass because I wanted to just avoid necessity of typing in indexes to every actor on the level by hand (With possibility of screwing something up in the process), but if I could have a utility that does it for me via script, then all I will have to do is just to not forget to hit it before final level compiling. Thanks!
So if I want to know which object to assign what property upon loading the level, what would be the best option? With actors of class thing I thought about it firing at the start of the level once, gather all actors into array and then assign them integer value in order of their position in array. And save-load system would use these integers to identify objects and assign correct parameters to them.
Exactly. You can also print an error to the log if you see that an ID is 0 (or -1 or whatever you set as default), so that you’ll see immediately if you have forgotten to press it.
Glad that it helped!
Welp, blutility doesn’t work for me (tutorial say that a button should appear after I create a function in it, but nothing shows up).
You have to create an event if I remember right, also, did you check the “Run in Editor” checkbox in the detail panel?