Unitialized DataAsset in AActor::OnConstruction

In the project I’m working on I’m using the OnConstruction function in an actor to update some properties using a custom DataAsset everytime the actor is moved in the editor. As long as I’m editing the level or it’s the first level loaded into the editor this is fine, but if the editor opens to a different level and I then load the level my actor is in then the DataAsset I’m using just isn’t initialized.

I repro’d this with the following steps:

  1. Create a new C++ project with a blank template
  2. Add 2 C++ classes to the project: one DataAsset and one Actor
  3. Add a float UPROPERTY to the DataAsset class, defaulted to 0.0f
  4. Create a new instance of your DataAsset in the editor, change the float value to some number greater than 0
  5. Override the OnConstruction function in the actor class from step 2, call LoadObject and get the object from step 4
  6. Add check(asset->floatProperty > 0.0f); to the OnConstruction function
  7. Create a new level in your project, put an instance of your actor into the level
  8. Make sure “Edit->Editor Preferences->Loading and Saving->Load Level at Startup” is set to “None”
  9. Restart the editor
  10. Load your level from step 7

This should cause the check from step 6 to fail. I have found that a workaround for this is to open the DataAsset from step 4 in the editor before opening the level but that’s not foolproof since it’s entirely possible to forget to so that (or just not know that’s required since I’m not working by myself).

Attached here is the repro case that I created. This also occurs in 4.12 so doesn’t seem to be a new bug.

Hey -

I was able to reproduce the error (the check not being triggered) when using File->Open Level to open the level from step 7. However I also found that by double clicking on the level asset in the content browser I did get the check to trigger. This leads me to believe that, rather than the data asset not being initialized, there is a difference in the way the level is loaded that is causing the issue. This difference in level loading has been reported here: Unreal Engine Issues and Bug Tracker (UE-36532) . You can track the report’s status as the issue is reviewed by our development staff.

Cheers