That’s my first Topic in this forum. I started Unreal a few weeks ago but I have some C++ Knowledge. I want to create a class InteractableObejcts, where some other Objects inherit from. I Create with CreateDefaultSubobject an BoxComponent and set this to RootComponent. After that I want access to the RootComponent with GetRootComponent() but it’s every time nullptr. Maybe I do anything wrong, but I saw the same code in Unreal Source Code Character.h/cpp and if I create a class which inherits from Character.h I can access the CapsuleComponent which is the RootComponent of the Character with GetRootComponent(). I didn’t figure out what I do wrong. Is it because it’s Unreal API Code and not the Game Code? If you need more Informations, please ask. I read a lot the last 2 Days in the forum but didn’t find an answer to my question.
Edit: It seems like the RootComponent doesn’t store the BoxComponent as it’s RootComponent. In Scope of the Constructor the RootComponent is right assigned as the BoxComponent but in other methods the RootComponent is nullptr.
Edit: I figured out that the problem is that the RootComponent gets deleted while optimization. I don’t know why Unreal does this but how can I avoid this?
Sry for the edits, I want to work and I’m annoyed about this problem because it cost me so much time.