This is the weirdest bug I’ve found. This has happened to me on multiple occasions with different components and I have no idea what is happening.
The long and short of it is that I have a component which gets initialized in the C++ constructor and is allocated memory. As soon as the constructor completes, that memory is deleted and set to NULL.
I thought that for sure, this component is being garbage collected and I triple checked it. I even stepped through the engine side code, line by line, especially in the garbage collector, and I did not see my component in the collection queue. Something else is happening and my component is getting deleted and set to null, and I can’t seem to find where its happening.
I tried deleting all of my intermediate files and DDC. This had zero effect. The result was the same.
However, if I rename my component from “MyComponent” to “MyComponent2”, it works perfectly fine.
If I rename MyComponent2 back to MyComponent, it gets deleted again.
I have even set my component to private and created a const “GetMyComponent() const” getter method to make sure that no other class is messing around with the component. This makes no difference.
I suspect that there is something happening internally within the blueprint, where a stale value or symbol is getting stomped. To test this hypothesis, I left the component name unchanged, so that it would ‘fail’ and get set to null after the class constructor has completed. Then I created a brand new blueprint which inherited from the same base class and ran the game. Sure enough, that fresh new blueprint ran without any problems: The component value persisted after the constructor ran.
What is happening here? Is there something I can do to “flush” the existing blueprint and have it rebuild its internal symbol lookup tables?
Update:
I seem to have found a fix. Right click on your offending blueprint, go to “Asset Actions”, and then “Reload”.
make sure you save everything else before you do this because the reload will cause dependencies to reload themselves as well, which has a chance of having unchecked null references which cause an editor shutdown.
Update 2:
Oh wait, no, the above update is hit and miss.
Duplicate the blueprint and replace the old one with the duplicated one. Doing stuff in the constructor after you created a bp child of it sometimes causes problems.
Had the same issue, needed to rename the Component Variable (“MyComponent” → “MyComponent2”), Rebuild, and then Rename back for the Component in Editor to update.
Bump. Can confirm this still reproduces in 5.1 pre-release. In my case, it happened when I inherited one character bluprint from another. No amount of reloads or duplication helped - I had to delete that actor completely and create a new one.
The component was there in constructor, but was NULL on BeginPlay.
THANK YOU!!! I was pulling my hair out. In 5.2, I only get the problem with UTextRenderComponent. Your suggestion of gutting the UPROPERTY annotation was a good work around to this unreal engine bug. (I ended up just using UPROPERTY() )
I know this isn’t ideal, but if you can, just close Unreal and Revert any changes you may have to the Blueprint *.uasset. That should pretty much fix any serialization issues that may have occured between your last commit. Unfortunately you’ll need to redo any work you had done to that blueprint.
ok, just delete the UPROPERTY and compile the code, then add UROPERTY back and compile it again. No need to reboot UE or change your Component’s nameAt least that’s how I did it. It worked
I had the same problem with UE5.3.2. I created a CombatComponent that wasn’t empty in its constructor, but it was empty when I started the game. When will UE fix it