I have a traffic system where the AI cars the find there own route, this takes some CPU power and with alot of cars on the map this causes alot of stuttering.
Ive created Route Actors where the already calculated routes are stored.
So I want to save the route actor to the level map so that they are persistent.
As I know, you can’t store and save Actors this way. Actors are special objects placed in World, when destroyed, it will be destroyed from your array too.
Correct way - if you want to save Actor position (and other values) you should create Object where you will store all Actor variables with Actor Class. Then you can add this Object to array and save it for example.
If you need next time spawn same Actor in it’s place, you have to find right Object, check and spawn Actor from saved Class with all saved in Object variables.
Here more solutions with Data Tables and other, but this is still simplest and I think correct. All other solutions are based on save Actors variables only not Actors itself too.
For detailed solution you should find good tutorial for inventory items, this is same idea how to do it.
If anybody know simpler solution, I will be very happy - please post here.
I will look into Data Tables, what I want so save is the RouteName (firstnode’s name+lastnode’s name) and an array of nodes that will form the route. Seems like a data table will work in that case.
Seems that you cannot write data to a data table, wich kinda makes it hard since I don’t know every possible route in the game. I want the game to figure it out and if it ever found a route between the start and end point to re-use that route instead of finding it again.
TBH I did not know that a data table existed in unreal.
If you need to store just Name, it will be enough to use Array and Struct (combined). Objects are handy for easy management later, but if you need only names Array&Struct will be best.
You can also add all other variables in Struct Array, this is nice solution.
I not found good tutorial nor doc’s how to use Data Tables, but they are used, not sure with Blueprints only.
Anyway, you should store tracks maybe as splines or just set of track points stored in 2D array as set of points for each track. Here no real 2D arrays, but you can do it using Arrays with Struct of in simple words - array of Struct - where Struct can be array too.
I’m using a Map now with a string (routename) and a struc with the route array in it.
Now I need to save that to a file when its updated, but seems to be a decent way of doing it.
TBH a way to make a writeable data table would be one of the best features UE4 can use.
Good advice - I read somewhere for what DataTables can be used, but never found working solution, just name is confusing - DataTables, so in my work I use Struct/Arrays.