Foliage instance save / load approach

Hi all, I’m working on the RTS project and came across the issue that I cannot save/load foliage instances that have been removed during playtime.
I’m spawning Foliage as trees and food, then units gathering it. Before gathering I’m removing foliage and spawning an actor there.
Now after I have saved and loaded all my foliage back with spawned actors.
I have tried this approach but it only works on the FPS in UE5 and my project is TopDown in UE4.27
I know that based on the UE documentation you cannot save Objects or Actors in Structure, so I understand why it doesn’t work for me, but I do not get why it works on the FPS template.
The main question is how to make it work and the best approach for this type of issue. I’m sure lots of people have done it before, I just cannot find how.

I have this error: Blueprint Runtime Error: "Accessed None trying to read property Foliage_11_51E175194C093D9159087AAF313699FB". Blueprint: RTS_GameInstance Function: Execute Ubergraph RTS Game Instance Graph: EventGraph Node: Remove Instance
which is correct as I’m trying to save Object in Structure so it is not saved there.
My structure:

My Foliage is a custom actor:
image

but with the default one I have the same error. Now before save and load I have this debug output:
image

and you can see the list of classes and indexes of the foliage, but after I save and load these data:


Green is what was loaded and blue is what is in the array that I have stored. As you see the indexes are there, but the Object is None.

I would really appreciate it if someone suggests a good solution for that issue as collecting locations of each foliage instance and then spawning line trace there and removing it looks way over usage of CPU for this task.

Best regards,
Alexander

+1 , most open world games do this that have some sort of harvesting mining. but very little documentation on it.

Hi @Metalvenomuk I have done it this way:
First in the Foliage Static Mesh Component I added function that every time you exchange Foliage to Actor (Tree or PUmpkin in my case) it adds ID to the Game State array Foliage Instance Static Mesh posted by chuklov | blueprintUE | PasteBin For Unreal Engine
So the Game State can store it Save and Load, but after you load a game I use Remove Function and removing instances based on the stored ID’s: Remove FSM Component based on ID posted by chuklov | blueprintUE | PasteBin For Unreal Engine

Let me know if it helps.