I’m not entirely sure what you’re trying to accomplish by creating the component before the actor class, but part of your problem is that you’re casting a component to an actor, which shouldn’t work since they have no parent-child relationship.
Sorry about not providing the proper cast. You should try to cast it to the weapon’s class type, or its parents. And the better way to do it would be to create the weapon, then get its component. I’m still not quite sure why you’re doing it this way.
Getting the actor from the component makes sense when the WeaponClass is a blueprint which you may want to be able to change in the editor, so this should be initiated in the constructor.
Getting the component from actor may work using the post-constructor, since WeaponClass is still not initiated in the Constructor, but still you need to provide the class in the blueprint.
So, in this case, it makes no sense to do the extra job to init the component from actor in post-constructor, when it’s cleaner (and much more common) to init the actor from component in the constructor.
This approach is common because of the flexibility of being able to change the class in the editor and see the result instantly in the editor. I recommend this approach even if you don’t ever plan to change the class, because, usually, you will want to change it, for various reasons.
Thanks for your ideas, I didn’t thought this way : D
With post-constructor you mean BeginPlay?
Creating an actor in the Component is an interesting idea. But because it is the player I want to possess it’s needed to tell the Controller that he controls this pawn and if I want to create two components it wouldn’t work.
I try to learn from any source I can, in this particular case I knew from my experience that it’s logic to have a function or two between constructor and BeginPlay. Then I googled for “ue4 c++ actor post constructor”. Looking into code also make a lot of sense.