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"

C++ Cast NPC Character into Player Character

Hello World, C++ noob here. I have a project made in blueprint, and I'm trying to convert everything in C++. I'm having only 1 problem. I have an NPC Character (NPCInteractive), an AI, and I want to cast it into my Player Character, because I have fonctions into my NPC that I want to call in my Player. Here is the CPP file:

     #include "WithLoveFromTahitiCharacter.h"
     #include "NPCInteractive.h"
         // launch dialogue input
 PlayerInputComponent->BindAction("LaunchDialogue", IE_Released, this, &AWithLoveFromTahitiCharacter::LaunchDialogue);
     void AWithLoveFromTahitiCharacter::LaunchDialogue()
         ANPCInteractive* NPCInteractive = Cast<ANPCInteractive>(GetOwner());
         if (NPCInteractive != nullptr)
             UE_LOG(LogTemp, Warning, TEXT("OVERLAP"))
             UE_LOG(LogTemp, Warning, TEXT("NULL"))

When I press the LaunchDialogue button, it return always NULL

Here is the .h file:

 #include "WithLoveFromTahitiCharacter.generated.h"
 class ANPCInteractive;
 class AWithLoveFromTahitiCharacter : public ACharacter

Thank you for your help guys and sorry for my english (I'm stuck for 1 week now lol).

Product Version: UE 4.19
more ▼

asked Jun 27 '18 at 08:09 PM in C++ Programming

avatar image

32 3 4 9

avatar image PascalSantos Jun 27 '18 at 10:48 PM

I'm really not sure what exactly you want to achieve. How I understand what you want.... On Button Press you want to interact with an NPC. And the Interaction is defined inside the NPC.

What I would do: -On Button Press-> Get all overlapping actors of class npc / use traces to get the npc (depends on your System) -Use the NPC reference to call your function

avatar image MasBASS Jun 27 '18 at 11:29 PM

Hello sir, sorry for the late, you're right, here is the blueprint for more detailsalt text

overlap.png (455.7 kB)
avatar image PascalSantos Jun 28 '18 at 11:26 PM

So why dont you Just reproduce the blueprints in c++? They seem to be decent. There should be more than enough resources to find about Bindung to the overlap Events in c++ And you should be good to go. Because currently you are missing any reference to the NPC so your cast will always fail

avatar image MasBASS Jun 29 '18 at 01:53 AM

In the first post, I was just trying to understand how Cast work and yes right now I'm working with a OnComponentBeginOverlap event with cast, still not working XD but, I'm still learning :)

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

0 answers: sort voted first
Be the first one to answer this question
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