x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Crash when spawn actor

I have c++ function for spawn actor, when i compiled i had no error, but when i try to use it in blueprinti so i have crash. 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);
     
 
 }

alt text

Crash report

UE4Editor_Engine UE4Editor_Engine UE4Editor_MyProject_7534!UMyBlueprintFunctionLibrary::Spawn() [d:\sasha\myprojectszxc\myproject\source\myproject\myblueprintfunctionlibrary.cpp:29] UE4Editor_MyProject_7534!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!UEditorEngine::CreatePIEGameInstance() [e:\ue4git\unrealengine\engine\source\editor\unrealed\private\playlevel.cpp:3012] UE4Editor_UnrealEd!UEditorEngine::PlayInEditor() [e:\ue4git\unrealengine\engine\source\editor\unrealed\private\playlevel.cpp:2259] UE4Editor_UnrealEd!UEditorEngine::StartQueuedPlayMapRequest() [e:\ue4git\unrealengine\engine\source\editor\unrealed\private\playlevel.cpp:1048] UE4Editor_UnrealEd!UEditorEngine::Tick() [e:\ue4git\unrealengine\engine\source\editor\unrealed\private\editorengine.cpp:1244] UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [e:\ue4git\unrealengine\engine\source\editor\unrealed\private\unrealedengine.cpp:361] UE4Editor!FEngineLoop::Tick() [e:\ue4git\unrealengine\engine\source\runtime\launch\private\launchengineloop.cpp:2427] UE4Editor!GuardedMain() [e:\ue4git\unrealengine\engine\source\runtime\launch\private\launch.cpp:142] UE4Editor!GuardedMainWrapper() [e:\ue4git\unrealengine\engine\source\runtime\launch\private\windows\launchwindows.cpp:126] UE4Editor!WinMain() [e:\ue4git\unrealengine\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]


Product Version: UE 4.10
Tags:
sc1.jpg (136.3 kB)
more ▼

asked Jan 07 '16 at 09:45 PM in Bug Reports

avatar image

SashkoBchk
11 5 7 10

avatar image Sean L ♦♦ STAFF Jan 08 '16 at 03:55 PM

Hello,

Could you provide the full code from your .h and .cpp files that you are using?

This could potentially be a naming conflict, because each time you are spawning the actor, you are giving it the name "1". Try commenting this line out, and see if you get the same result.

 param.Name = "1";

avatar image SashkoBchk Jan 09 '16 at 10:12 AM

No its not help. I replaced my code but also crash

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);
  }
 

avatar image AlekseyIlin Jan 10 '16 at 11:07 AM

UE4Editor_Engine UE4Editor_Engine UE4Editor_MyProject_7534!UMyBlueprintFunctionLibrary::Spawn() [d:\sasha\myprojectszxc\myproject\source\myproject\myblueprintfunctionlibrary.cpp:29]

This is the line that caused the crash. Most likely because of dereferencing a NULL pointer.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hello,

I was able to solve your issue by making a few changes to the code.

 UWorld* AMyActor::gtW(AActor* actor)
 {
     //Check if the actor is valid
     if (actor)
     {
         UWorld* const World = actor->GetWorld();
         if (World)
         {
             return World;
         }
         else
         {
 
             GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "World - false");
             return NULL;
         }
     }
     //If the actor is not valid, return NULL
     else
     {
         return NULL;
     }
 }
 
 void AMyActor::SpawndA(class UClass* clas, class AActor* actor)
 {
     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 (gtW(actor) != NULL)
         gtW(actor)->SpawnActor(clas, &loc, &rot, param);
 }

So the first thing I did was remove your AMyActor variable from the SpawndA function, as it was unnecessary and was never being initialized. After this, I took the a.gtW out, and just called gtW(actor), as it would use the MyActor class to call GetWorld(). Finally, I implemented a check to see if the actor being passed in was valid, because if it wasn't then GetWorld would always fail.

Feel free to let me know if there are any further questions.

Have a great day

more ▼

answered Jan 11 '16 at 03:23 PM

avatar image

Sean L ♦♦ STAFF
43.9k 485 150 439

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question