BLUF:
I am trying to have my first person player, press a button and cast a line trace and have my AI character move to that point. I am unable to pass that vector variable from my player to my AI. Any ideas?
Here is how I have everything set up…
I have a Base Character blueprint that acts as the parent for my Base AI and and Base Player characters.
To Provide a little overview of the hierarchy I have created:
Base Character BP => First Person Player Character and Base AI Character.
Base AI Character => Team 1 AI Character and Team 2 AI Character.
Within that Base Character, I have a line trace event and use that break hit result to get a vector location which I set as a variable in the Base Character. I am calling this event in my first person character when pressing a button and it fires off to an interface. The interface has an blank input node and blank output node. Just using it to be able to reference the code among different characters. (which stemmed from me trying to have line trace code in my first person character an AI move to node in my AI Controller). In my mind, since that variable is set at the Base Character, I should be able to reference that variable as the AI Character (you know, because child inherits from parent). But that isn’t working. The variable at the AI Character blueprint still shows as 0,0,0 instead of the coordinates… which I can see is set on the Base Character when debugging. As mentioned, that doesn’t work, so I went on and tried to add a Dispatch to the end of the Base Character line trace code (after setting the vector variable). Within the AI Character blueprint, Event BeginPlay, it binds the dispatch and has the event attached to have the AI stop brain logic to stop running the Behavior Tree and then calls the AI Move To node. But For what ever reason, when adding BreakPoints, it never calls the event on the Binded Dispatch Node.
This is all very frustrating, because I figured this would have been far more simple. But several days later and I have made no progress.
Nowhere in the description did you explain how the referencing is done. How does the player know who the AI is? What if there are 10 AIs - how do we know which one to command?
The interface has an blank input node and blank output node. Just using it to be able to reference the code among different characters.
Can’t wrap my mind around this.
Not sure if what’s below helps but, at the most fundamental level, the setup could be as follows:
a character up on the right, AI Sphere drone in the bottom left:
Above, the exposed AI Drone variable allows me to reference something from the scene (there are other ways to reference, too). Below, we trace along the camera vector and use the previously set reference to tell the AI to move on the navmesh:
No interface or dispatcher is needed here. Interface makes communicating between unrelated classes easier. Dispatchers are mainly for call-backs.
The question stands - how do you reference the AI in the Player. Once you have the reference, you can send a message through the interface, sure. But we need to know who to send it to first. How do we know that?
This is fantastic! Thank you! I didn’t mention how I am getting a reference to the AI because I am still working on that and I never know how much detail to include in these posts. As of now, I have it so when the AI uses perception and find the player, I use that to initiate the code for having the AI follow the player. I am working on referencing the particular AI because as of right now, all I can figure out is by having a sphere collision attached to the player and reference the AI when it enters that sphere… which I am not a fan of so I have been avoiding it due to not being able to figure out how to handle the cases where more than 1 AI enters that sphere. So I am trying to reference the particular AI by Gameplay Tags (which I haven’t been successful with).
So I will say this is resolved. Just put a sphere collider on player character and the AI that overlaps it is the person I reference for the Move To Location node.
But I also have the AI set to a specific Gameplay Tag. Eventually I will set that as the way to reference the AI.