[C++] Custom component set to null by FObjectInitializer after editor reload
I have stumbled across a problem that I can't seem to fix regarding components. I am using C++ on Unreal 4.8.3, and creating blueprints from these classes to be able to mess around with variables without recompiling. Although I have a solid programming background, I am new to the Unreal API and so I am not sure if it is a problem with my component or something unrelated. I'll try and walk through the steps that cause the issue, because it is happening consistently. Please note that there is other code in the project, but I have tried to isolate the project just to the code listed here. I think I have stripped it enough that no other code should be affecting the issue, but feel free to throw queries at me if there is anything suspect.
First, I create new blueprint based of my class. The component is there and working fine, which can be seen in the details panel.
At this point, I compile and save the blueprint, just to be sure, then hit every save button under the sun to make sure it is all saved (save all, level save, etc.). I set the default pawn to this new blueprint, rebuild the entire project, and PIE. After all this, the component is still alive.
Now I close the editor, and rerun the editor (this whole time I have been hooked up to the VS debugger, I close the editor using the X in the corner, then rerun by running the local VS debugger once more). Once I have fired the editor back up, the component dies (see the details panel, also disregard the change in class name, I did this a second time to make sure the class name had never been used but the results were identical).
Now, the reason I think I may be doing something wrong with the script component is that the camera boom and top down camera components both survive just fine, and they are set in exactly the same way as the script component. By setting a data breakpoint on the pointer (8 bytes), the pointer is set back to null in the FObjectInitializer destructor. The stack trace is as follows.
Along with the code and locals of the top of the call stack (note that ScriptComponent is null in both Obj and DefaultData, yet TopDownCameraComponent and CameraBoom are both fine).
Here is all of the C++ code. I have stripped out everything bar the constructor and the properties in question (I don't mean for the sake of shortening the code, this is all of the code that is being compiled relating to this actor and component, everything else is commented out).
There is a bug in our system (UE-18284) that sounds similar to the issue you are experiencing. I'd like you to perform a quick test. Instead of using VisibleAnywhere on your Script Component, try using EditAnywhere, and see if you get the same results.
answered Jan 07 '16 at 04:10 PM
Sean L ♦♦ STAFF
A lot of people had similar issues to this in the past, here's one related post: https://answers.unrealengine.com/questions/200300/changing-component-types-causes-corrupted-bp.html
If you've tried recreating the blueprint from scratch and that hasn't helped, then I think you are most likely looking at an engine bug and will need to upgrade. I haven't experienced this issue again myself recently, and the engine code snippet you posted is different from the current version, so I suspect this issue has been fixed since 4.8.
answered Jan 07 '16 at 11:41 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here