Need help getting location of object

Hello, I’m trying to make a basic AI for a VR Table Tennis game. Essentially, the ai paddle needs to follow the ball along the x and z axis. My only problem is, I cannot figure out how to get the location of my ball. It should be noted the the ball is an actor blueprint.

Basically, I need to know how to get the target for Get Forward Vector and Get Actor Location.

I’ve considered using a “Get Actors of all Class” node, but I don’t know how to execute it. (I’ve attached a picture)

In this AI blueprint, create a new variable and instead of using one of the normal variable types … begin typing out the name of your ball’s blueprint instead. Make sure to choose Reference from the popup list instead of one of the other three options. Call it something easy to remember, like “GameBall”. That variable can then be used to access the ball and anything associated with it, such as its Actor Location, here in this blueprint. ie: You’ll be able to connect it straight to the open target pin you have highlighted in your image.

The problem then is that when the game starts, this variable reference will be empty. If a ball goes off the table and you kill it in order to spawn a different one, that reference will go empty also. So it’s up to you to figure out the best way to populate this variable when you make a new ball. There’s a lot of ways to do this, and some are better than others.

Getting all actors of class would work, but when put in your Tick here you’d basically be searching all the map assets for the ball about 60 times every second. So that’s no good. [BTW - The way to do that is to drop down a Get All Actors of Class node, pull the ball’s class type in the dropdown, then pull off the back pin and type “Get”. If there’s only 1 ball, then this will appear on index #0 as an object type of your game ball.

When the ball spawns into the game, it could try to search out your AI controller and drop a reference to itself in your AI controller’s new GameBall variable reference. That’s better because you only do it when the ball spawns and not a bunch of times every second. But it could be hard to get a handle on the AI controller this way because that controller is not directly controlling the ball, right.

So what I suggest is that you make your own Game State blueprint and add it to your Game Mode. Whenever you spawn in the ball, the AI controller and/or the player himself - have them all register themselves with the Game State on each item’s Event Begin Play. So let’s say you stick three new variable references in the Game State for MyAIController, MyGameBall and MyPlayer. On the ball’s Event Begin Play, drop a Get Game State node - then Cast To [NameOfYourGameStateBP] - then set MyGameBall to a reference to Self. Over in the Game State, you could make a function that passes the new reference of MyGameBall back to anybody that needs to know something about the ball. For example, you could set MyAIControllers.GameBall from step #1 == MyGameBall. Using a Game State is a very easy way for all the blueprints running around your game to check in on each other.

Later when you’re more comfortable with all this, you can try event dispatchers and bound events and all that so the ball blows a trumpet upon spawn and broadcasts a birth announcement to anybody who cares to know - but that’s going to get you pretty frustrated if you try and figure it out right now. Hope this helps!