Reply To: Bug: Reference lost after recompile

FlowCanvas Forums Support Bug: Reference lost after recompile Reply To: Bug: Reference lost after recompile

#2363
grendelgerard
Participant

I managed to make a dirty fix. Which perhaps breaks more, but it might give some direction for the real fix:

1. In Graph::Serialize I store a copy of the _serializedGraph and _objectReferences

2. In Graph::OnValidate I restore the copy to _serializedGraph and _objectReferences (at this point Unity serialization has resolved the “null” reference) and call Deserialize()

3. Also in Graph::OnValidate I set a flag to true

4. In Graph::OnEnable I set this flag to false

5. In GraphOwner::Validate I check if the flag is true, if so, I copy graph._serializedGraph to boundGraphSerialization and graph._objectReferences to boundGraphObjectReferences

This is quite a dirty fix and I don’t know if I handle all the serialization cases. But what it does is:

During OnBeforeSerialize Unity has not resolved all references yet, resulting in Graph to lose its reference. I store the unresolved references at this point.

During OnValidate Unity has resolved all it’s references. I restore the serialized data to graph and Deserialize. Effectively restoring the graph to its correct state.

GraphOwner tries to Deserialize the Graph also, using the corrupt serialized data. So in the case this is triggered, I give graphOwner the correct data, just before it serializes.

I think for the correct why to fix this, is not handling reference in the OnBeforeSerialize state, but wait until the Validate state (or another state) and handle the serialization then.

EDIT: In my example scene this worked. In the large project (which also uses prefabs) references are still lost