I created c++ Actor class, i wrote non-static function for get World. I made child Blueprint from my class, add it to scene, i am trying to spawn but still have crash.
I need some functions that will be spawn enemy in the specific formations it will be my attack wave. I know that it can be realised in Blueprint but it is more easily to make it in C++. And finally i want write this function, because here question arises what the engine is it where impossible to realise so easy function.
MyActor.h
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
UWorld* gtW(AActor* actor);
UFUNCTION(BlueprintCallable, Category = "MyActor")
static void SpawndA(class UClass* clas, class AActor* actor);
};
MyActor.cpp
UWorld* AMyActor::gtW(AActor* actor)
{
UWorld* const World = actor->GetWorld();
if (World)
return World;
else
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "World - false");
return NULL;
}
}
void AMyActor::SpawndA(class UClass* clas, class AActor* actor)
{
AMyActor a;
FActorSpawnParameters param;
FVector loc = FVector(0, 0, 0);
FRotator rot = FRotator(0, 0, 0);
if (clas == NULL)
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "clas - false");
if (a.gtW(actor) != NULL)
a.gtW(actor)->SpawnActor(clas, &loc, &rot, param);
}