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"

Function when called crashes the editor and game

Whenever this function is called, it causes the whole editor to crash.

 void AImpulse_AOEcpp::launchCharactersInArea() {
     UWorld* world = GetWorld();
     TArray<AActor*> ListOfCharacters;
     GetOverlappingActors(ListOfCharacters, TSubclassOf<ACharacter>());
     for (int Actors = 0; Actors < ListOfCharacters.Num(); ++Actors)
         AActor* CurrentActor = ListOfCharacters[Actors];
         ACharacter* CharacterToLaunch = Cast<ACharacter>(CurrentActor);
         CharacterToLaunch->LaunchCharacter((FVector)(0, 0, LaunchPower), true, true);

Does anyone have any clue why this is? Because it crashes the editor I can't try to see whats wrong.

Product Version: UE 4.18
more ▼

asked Jun 11 '18 at 11:10 PM in C++ Programming

avatar image

14 2 3 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

It seems you missed out some null check.

CurrentActor is safe because for loop itself guarded it once from de-reference with invalid index. Casting on CurrentActor is also safe because casting on nullptr will get nullptr.

However, CharacterToLaunch may fail because not all AActors are ACharacters. In which case some of it would be nullptr. Then attempt to call a function that belongs to ACharacters from non-ACharacters, will crash for sure.

Let me know if this fixed your issue with this:

 if(CharacterToLaunch != nullptr)
     CharacterToLaunch->LaunchCharacter( FVector(0,0, LaunchPower), true, true);
     UE_Log(LogTemp, Warning, TEXT("Cast failed"));

more ▼

answered Jun 12 '18 at 05:30 AM

avatar image

182 1 4 7

avatar image Hemlock Jun 12 '18 at 04:36 PM

I tried this but it still crashes. I don't suppose that you have any more ideas?

avatar image Hemlock Jun 12 '18 at 04:40 PM

Nevermind I found the problem. Your solution was correct.

avatar image Hyrex93 Jun 12 '18 at 06:52 PM

Highly recommended to install editor symbols on the engine as well, so whenever the code crash, it will tell you exact line it crashed. In addition, use DebugGameEditor build for tracking variable values. DevelopmentGameEditor sometimes hides pointer information away, and some code will never breakpoint. If you open up using .uproject, it is default using DevelopmentGameEditor build.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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