x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Save Game object that contains a FSoftObjectPtr

Hi,

It is currently not possible to create a save game object that contains a FSoftObjectPtr. In my case the object ptr indicates a checkpoint actor to respawn at.

Save games are serialized via UGameplayStatics::SaveGameToSlot which in turn uses FObjectAndNameAsStringProxyArchive.

FSoftObjectPtr can basically be expressed as strings but the archive does not support serializing it.

Is this intended behaviour?

Kind Regards, Jacomi

Product Version: UE 4.20
Tags:
more ▼

asked Oct 09 '18 at 07:58 AM in C++ Programming

avatar image

bfg_jmconradie
1 1

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Hi there, FSoftObjectPtr.: Pointer to UObject asset, keeps extra information so that it is works even if the asset is not in memory FSoftObjectPtr is a type of weak pointer to a UObject , that also keeps track of the path to the object on disk. It will change back and forth between being Valid and Pending as the referenced object loads or unloads. It has no impact on if the object is garbage collected or not. FObjectAndNameAsStringProxyArchive: Implements a proxy archive that serializes UObjects and FNames as string data. Serializing the address won't work. You can't just write down the exact memory address, because there's no way to guarantee that objects on the next run will be able or not. Serializing the pointed object in each place where we have a pointer wont work: This would be a lot more data that we'd need to serialize If we had weak pointers creating a circular dependency we wouldn't be able to stop and retrieve that connection later. There is no way to merge the same objects into one when deserializing. So i suppose that it would be an intended behaviour.

Regards.

more ▼

answered Oct 09 '18 at 10:09 AM

avatar image

ZDron3
66 1 6 7

avatar image bfg_jmconradie Oct 09 '18 at 10:43 AM

I understand that the memory address to the UObjects and any UObjects that are not part of an asset but created at run-time cannot be restored via FSoftObjectPtr.

For the above case I am referencing an AActor in a ULevel. When the level is loaded, the actor will be instantiated and the FSoftObjectPtr can be resolved returning the new, correct memory address to the instance in question. If the ULevel asset was changed and the actor question be removed, then the FSoftObjectPtr will never get resolved (which is to correct and expected).

The FSoftObjectPtr basically uses the Asset Path Name and Sub Object Path as a unique identifier instead of the object's memory address. Considering this it would make sense that they can be serialized via FObjectAndNameAsStringProxyArchive since they reference the object in question in a soft manner via strings and names to begin with.

Kind Regards, Jacomi

avatar image ZDron3 Oct 10 '18 at 09:40 AM

I understand the point that you are trying to make and you are right about "Considering this it would make sense that they can be serialized via FObjectAndNameAsStringProxyArchive since they reference the object in question in a soft manner via strings and names to begin with" and you can do absolutely do that i.e you can serialize the "Path" of the FSoftObjectPtr by converting.So in short you can serialize the objects(FName) and the path's(FName) used by the FSoftObjectPtr but no the pointer itself, here come the reasons i had listed above : Serializing the pointed object in each place where we have a pointer wont work: This would be a lot more data that we'd need to serialize If we had weak pointers creating a circular dependency we wouldn't be able to stop and retrieve that connection later. There is no way to merge the same objects into one when deserializing. The reason to not serialize pointers is because tracking where pointers are pointing and whether we need to serialize their data is a non-trivial problem. Consider a really simple example where you have an std::vector and some T * pointing to some items in that vector. We as humans can easily understand that the vector is managing this memory, but ue has no easy way of inferring this. With pointers a lot of machinery is necessary to prevent duplicate serialization this may add a completely unwanted amount of bloat to the library and the API.

PS : All of this is just a educated guess,for the actual reason i think it would be better if someone who's actually worked on the UE4 Architecture with the source code can give a better explanation on the same.Hope you get the answer you're looking for ^ ^.

Regards.

(comments are locked)
10|2000 characters needed characters left

Ok it seems that this feature is scheduled for release in the next version.

See Unreal Engine 4.21 Preview, the Core Improvements section.

Kind Regards, Jacomi

more ▼

answered Oct 11 '18 at 12:05 PM

avatar image

bfg_jmconradie
1 1

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question