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