Announcement

Collapse
No announcement yet.

Weirdest bug: Component set to null after constructor completes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Weirdest bug: Component set to null after constructor completes

    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?


    #2
    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.
    Last edited by Slayemin; 10-01-2018, 09:01 PM.

    Comment


      #3
      Originally posted by Slayemin View Post
      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.

      Comment

      Working...
      X