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"

Casting AActor* to PlayerClass* - Engine crash

First off hello, this is my first post here, hope I make it understandable enough.

I tried to find someone with a similar problem to mine (not just on here) but I sadly didn't find anything.

So I'm making my own post.

The problem is that the engine crashes every time my code gets to the line that has the Cast method on it.

 void ASpell::OnPlayerEnterHealArea(UPrimitiveComponent * OverlappedComponent, AActor * OtherActor, UPrimitiveComponent * OtherComponent, int32 BodyIndex, bool bFromSweep, const FHitResult & SweepResults)
 {
     if (!OtherActor->IsA(AProjectNameCharacter::StaticClass())) return;
 
     AProjectNameCharacter* NewCharacter = Cast<AProjectNameCharacter>(OtherActor);
 }

Sadly the crash report doesn't give me any information.

This also happened on 4.16, so I can safely assume that it's me that is doing something wrong, since I just recently started working with UE4.

If you need more information I'd be happy to answer any questions.

Thanks in advance!

Product Version: UE 4.15
Tags:
more ▼

asked May 26 '17 at 11:45 PM in C++ Programming

avatar image

Liryon
1 1 1

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

2 answers: sort voted first

Hey I found the solution for my problem.

I should really read up more on the Software I'm working with, maybe then I would've known that Unreal has built in Garbage collection.

So my problem was that I attempted to delete a bunch of things I shouldn't delete (apparently) because it'll make the Editor crash.

Don't know what to say, I only have myself to blame for this.

Learn from my mistakes. lmao

Anyway, thanks to anyone that tried to help me, I really appreciate you guys.

more ▼

answered May 27 '17 at 01:54 AM

avatar image

Liryon
1 1 1

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

Instead of answering directly I'm gonna show you a very useful tool to help you find the problems generated by this kind of issues, in VS you can go into Debug->AttachToProcess and from there just attach the UE4Editor.exe (your editor instance for that game). Now when you run the game and this issue occurs you will have a nice break in your code showing you the state of the variables and all the info you may need.

Now for the answer to your question, I assume that the cast fails (since you seem pretty sure about the game breaking when it reaches your line of code), try using an auto NewCharacter = Cast(OtherActor); instead to see if saving the type in question is the issue here or the cast itself.

If you already knew about attaching to process from VS then I apologize and hope that someone else finds this information useful in the future :)

more ▼

answered May 27 '17 at 12:04 AM

avatar image

nullbot
296 11 12 16

avatar image nullbot May 27 '17 at 12:09 AM

For some reason I cannot spell the cast the right way:

 auto NewCharacter = Cast<AProjectNameCharacter>(OtherActor);
avatar image Liryon May 27 '17 at 12:30 AM

I just tried that and it still crashes.

When I try casting from UClass* (OtherActor->GetClass()) the cast is just unsuccessful but the engine doesn't crash.

avatar image ExtraLifeMatt May 27 '17 at 12:59 AM

Have you verified OtherActor isn't null?

Change this line:

 if (!OtherActor->IsA(AProjectNameCharacter::StaticClass())) return;

to

 if (!OtherActor || !OtherActor->IsA(AProjectNameCharacter::StaticClass())) return;


avatar image Liryon May 27 '17 at 01:10 AM

I think IsA() does that automatically but I did it anyway and it's still crashing.

(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