Fixes a bug with default values not beeing correctly propageted to ot… #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes two closely related bugs. The root of the problem of both bugs is that you are serializing only those properties that are different from class default object (CDO).
The first issue with this approach is that the user can set a different default value for the component variable inside an actor (e.g., true while CDO would have false). Then modify this value in an actor instance inside a prefab such that it is equal to the component CDO (i.e., false). In such a case, the value will not be serialized since HasDefaultValue method will return true. However, when spawning the prefab, the (wrong) default value from the actor (i.e., true) will be used. Therefore you need to use a CDO object of the component's owner to retrieve the correct default values. This approach, however, works only for native C++ classes as the blueprint classes do not have a correct CDO available. Therefore, I spawn a copy of the actor and delete it later in such cases. Maybe you (or someone else) can point me towards a better solution for blueprint actors as I am not familiar with how exactly CDOs works in this case.
Now on the second problem. When you change a property of an actor inside a prefab from anything back to the default value, this change is not propagated to existing prefabs. The problem is that you are reusing existing actors in the spawned prefabs. Since the value is not stored (being the default one), this spawned actor will not be updated correctly. The solution I come up with is to change the actor PrefabItemID inside the ActorData array in case the actor was modified when saving the prefab. This forces the plugin not to reuse the existing actor if it was modified, and it spawns a new one instead.