Hello all! Still new to C++ and Unreal as far as C++ goes.
I am trying to get the reference of a weapon to get a Static Mesh Component from it. I am able to spawn the weapon and attach it to my character within BeginPlay():
I think you might be misunderstanding the purpose of static variables. They should be used rarely and only for things that you only ever want one of, regarldess of how many objects of that class are created. If you have a class ANPC and have a static variable within that class (e.g. static float Health), then Health is only created once and is shared by all NPCs, which isn’t normally desired behaviour but can be very useful in some cases.
To fix your problem, you’ll probably want to create the WeaponRef variable in your .h class
e.g.
private:
UPROPERTY(Transient)
class AWEA_Base* WeaponRef;
I had a feeling it may have been due to needing to use a UPROPERTY but I had no idea what to use! I will do some studying on them tonight.
One last question if you don’t mind though, do you know how I can get this to work? I am trying to spawn projectiles at the WeaponRef’s child static mesh (a static mesh I have added in bp)
I have already done something similar with attaching the weapon to the characters hand previously… But I am not sure what is going on here.