Hi,
I’ve created an Static class to store all of my weapons meshes.
It allows me to create a lot of pawns set theirs weapons on the fly
so I have my Uclass :
UCLASS()
class MYPROJECT2_API AIWeapon : public AStaticMeshActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AIWeapon();
UPROPERTY()
TArray<UStaticMesh *> mStaticMeshs; // ARRAY OF WEAPON MESHES
static AIWeapon* getAIWeaponInstance();
void InitAll();
};
and the CPP with it :
AIWeapon::AIWeapon()
{
}
void AIWeapon::InitAll() {
UE_LOG(LogClass, Warning, TEXT(" Init WEAPON 1 "));
static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshOb_AW2(TEXT("StaticMesh'/Game/WEAPONS/SWORD.SWORD'"));
mStaticMeshs.Add(StaticMeshOb_AW2.Object);
etc .....
}
AIWeapon* AIWeapon::getAIWeaponInstance() {
static AIWeapon* IWEAPON;
if (IWEAPON == nullptr || !IWEAPON->IsValidLowLevel())
{
UClass *IWEAPONclass = AIWeapon::StaticClass();
IWEAPON = (AIWeapon*)ConstructObject<UObject>(IWEAPONclass);
IWEAPON->InitAll();
}
return IWEAPON;
}
so this here “works” good
When I game start I’m in the
MyGameMode
MyGameMode::MyGameMode()
{
// first init of weaponInstance
auto initBase = AIWeapon::getAIWeaponInstance();
// first call and init of the meshes
}
and later on, every pawn wills call
auto initBase = AIWeapon::getAIWeaponInstance();
and get theirs meshes perfectly.
BUT
Every time I launch again the project in the editor, the object
mStaticMeshs
became invalid (the
mStaticMeshs.Num()
return -55675335…)
I think the problem is caused by because
the first init is done in the
MyGameMode
and after that every getAIWeaponInstance() are done in
beginPlay
Any idea ?