cast to issue



Ok so I am struggling here with casting it feels like no matter what it just doesnt work. So i made a whole new project and decided to see if I could do it on a very simple level and I still kept getting a failed cast. What am i doing wrong here. I have the right parent class i have the right reference called out under the defaults tab. IS there something else I should be doing?

A variable is not the actor. A variable is just a reference to an actor. What if there are 5 NPCs, which one of them would you like this variable to refer to? Currently it is not referring to any NPC.


You’ve created an artificial scenario for testing purposes which probably does not reflect how you’d do communication in a real project.
How does the player character know which NPC to talk to?

  • are we close to the NPC?
  • are we looking at the NPC?
  • are we clicking the NPC?
  • are we clicking on their icon somewhere in the interface?.
  • is the NPC your companion and is always with you?
  • perhaps there’s only one NPC in the entire game?
  • some other way?

What do you mean a variable is not the actor, am I not suppose to use a variable there?

So I am just trying to test out casting because it was not working on the project I am currently testing out having two NPCs striking up a conversation when they get near eachother. which is a rather complex system which I can share but I was trying to see if I could fix it on a simple version of it.

Does it have to be plugged into a collision event or something and I cant just have it plugged into a variable.

A variable is not an actor. It’s a memory pointer. Think of the variable that you have there as of an empty box that is the shape of a character. You can only fit characters in there, but the box is empty. Which character from the world would you like this box to store? The editor does not know which one you mean. This is a null variable.

What if you create a string variable and forget to type the text? You have a variable but no text inside. Same thing here.


Not necessarily. But if you’re choosing an NPC by proximity, then yes. You can use a variable, but we still need to know which NPC you want.


two NPCs striking up a conversation when they get near eachother.

What does the player BP have to do with this then? Let the NPCs talk to one another.


ok I undertsand that I have to define what goes into the variable which I thought I was by doing by setting NPCRef equal to NPCAI_dummy1 Am I not doing that right? I’m testing this with the player BP because it was not working between the NPCs and I am trying to simplify the process and see where I am going wrong with this.

This looks fine. So your player character is in the level, and you’ve manually picked an NPC instance from the level? Can you confirm?

Yes I have done that

In which case there’s something else here at play we cannot see.


So your player character is in the level

Are you sure that player start does not replace the player character? Do you have a player start? if you’re using a template, you surely do.

  • you’ve placed a player char in the level, set the ref to the NPC via instanced editable variable :+1:
  • the Game Mode spawns a new player character at Player Start ← this player character actor instance does not have the NPC reference set to a value
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.