OK guys this is getting ridiculous. At this point you’re not trying to get to an answer anymore. I’m turning off notifications. But before I do I will once again suggest the very easy (but not elegant way) to do what you want. Here is a sample class that does it. It will work fine as long as you are using the main thread – and since that’s the only place you can spawn from, this will always work as long as that doesn’t change.
H:
UCLASS()
class SHOOTER_API AMyActor : public AActor
{
GENERATED_BODY()
public:
AMyActor(const FObjectInitializer& ObjectInitializer);
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int MyVar1;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool MyVar2;
static AMyActor* Spawn(UWorld* world, int myVar1, bool myVar2);
private:
static bool ParamsSet;
static int Param_Var1;
static bool Param_Var2;
};
CPP:
int AMyActor::Param_Var1 = -1;
bool AMyActor::Param_Var2 = false;
bool AMyActor::ParamsSet = false;
AMyActor::AMyActor(const FObjectInitializer& ObjectInitializer)
: AActor(ObjectInitializer)
{
if(!ParamsSet)
{
UE_LOG(LogTemp, Error, TEXT("AMyActor spawned without using internal Spawn function!"));
}
else
{
MyVar1 = AMyActor::Param_Var1;
MyVar2 = AMyActor::Param_Var2;
}
}
AMyActor* AMyActor::Spawn(UWorld* world, int myVar1, bool myVar2)
{
AMyActor::Param_Var1 = myVar1;
AMyActor::Param_Var2 = myVar2;
AMyActor::ParamsSet = true;
AMyActor* myActor = world->SpawnActor<AMyActor>(); // fill Spawn() with parameters as you need
AMyActor::ParamsSet = false;
return myActor;
}