I wrote C++ function for spawn actor, when i compiled i had no errors, but when i try to use it in blueprints so i have crash UE. What i do wrong ?
void UMyBlueprintFunctionLibrary::Spawn(class UClass* clas )
{
FActorSpawnParameters param;
param.Name = "1";
FVector loc = FVector(0, 0, 0);
FRotator rot = FRotator(0, 0, 0);
UWorld* const World = GEngine->GetWorld();
World->SpawnActor(clas,&loc,&rot,param);
}
Daekesh
(Daekesh)
January 7, 2016, 1:40pm
2
You don’t need to set a name. It might be crashing because you’re using a short name with a single number. Is that a 1 or an L?
Do you have the actual crash message?
It was 1. Delete this line, it didint help, anywhere crash.
Crash mesage
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_MyProject_4074!UMyBlueprintFunctionLibrary::Spawn() [d:\sasha\myprojectszxc\myproject\source\myproject\myblueprintfunctionlibrary.cpp:28]
UE4Editor_MyProject_4074!UMyBlueprintFunctionLibrary::execSpawn() [d:\sasha\myprojectszxc\myproject\source\myproject\myblueprintfunctionlibrary.h:17]
UE4Editor_CoreUObject!UFunction::Invoke() [e:\ue4git\unrealengine\engine\source\runtime\coreuobject\private\uobject\class.cpp:4198]
UE4Editor_CoreUObject!UObject::CallFunction() [e:\ue4git\unrealengine\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:484]
UE4Editor_CoreUObject!UObject::ProcessContextOpcode() [e:\ue4git\unrealengine\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1755]
UE4Editor_CoreUObject!UObject::ProcessInternal() [e:\ue4git\unrealengine\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:698]
UE4Editor_CoreUObject!UFunction::Invoke() [e:\ue4git\unrealengine\engine\source\runtime\coreuobject\private\uobject\class.cpp:4198]
UE4Editor_CoreUObject!UObject::ProcessEvent() [e:\ue4git\unrealengine\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1050]
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll
No but world is Null. I changed my cod, but World always Null, and i dont know why it so, and how true get World.
void UMyBlueprintFunctionLibrary::Spawn(class UClass* clas )
{
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");
UWorld* const World = clas->GetWorld();
if (World)
World->SpawnActor(clas,&loc,&rot,param);
else
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red,"World - false");
}
Daekesh
(Daekesh)
January 7, 2016, 4:09pm
6
Is this a static function?
Daekesh
(Daekesh)
January 7, 2016, 4:30pm
8
You can’t do GetWorld from a static function. You need to pass in a actor or component to use GetWorld on.
Why aren’t you using the normal spawn actor function in blueprints?
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);
}