OnAfterDeserialize () is called, but the member asset reference is not deserialized.

Issue #219 open
wavebit created an issue

Hi, I want to operate the referenced object after deserialized, but it is not deserialized until I click the referenced asset file in unity editor. I created two asset files A and B, A references B. If I click A first, A's Parent will be null after deserialization. If I click B then A, the A's Parent will not be null after deserialization.

[CreateAssetMenu]
public class DomObject : SerializedScriptableObject
{
  [OnValueChanged(nameof(ParentChanged))]
  [AssetsOnly]
  // prevent cyclic dependencies
  public DomObject Parent;

  private void ParentChanged()
  {
    // Parent is null
    Health.Parent = Parent?.Health;
  }

  [OnDeserialized]
  private void OnDeserialized()
  {
    //
    ParentChanged();
  }

  /// <summary>Not yet documented.</summary>
  protected override void OnAfterDeserialize()
  {
    ParentChanged();
  }

  [OdinSerialize]
  public ObjectValue<int> Health;
}

Comments (2)

  1. Tor Esa Vestergaard
    • changed status to open

    I'm afraid you'll need to explain a bit more about the context, or provide a fuller example that we can actually put in a project and play around with, before we can help you with this. For example, how exactly does the ObjectValue<T> class work? It seems to be important somehow, but this example doesn't include it, so we can't test anything.

    Can you provide exact example code and reproduction steps that showase the issue you're having?

  2. Log in to comment