Assigning Spline Path to AI after it spawns.

I have 2 Spline Paths for my AI to follow. The problem is, I’m not sure how to make them know what path to follow once they are Spawned in.

I found another post from a while back that said they had a similar problem and they used the “Get Actors of Class” (Spline) and set the AI to use that Spline. But I’m not sure what nodes to use / connect. That’s all they said without any picture references to fill in the blanks. Does anyone know?

This is for Multiplayer. All AI are spawned Server Side as it should be. No issues with any of that. There are a random number of AI that spawn at once through Spawn Points. If I can just get a way to link up the Spline, I can handle everything else easily lol. I don’t know why I’m stuck on this part.

Hi @GoldFire376,

While a “Get All Actors of Class” would work here, you want to avoid using this node whenever possible as it has to search through each actor in the world and find their class to determine which actors you need. There is almost always a better way to handle this, usually in the form of a “manager” blueprint. Since it sounds like you’re not creating or destroying your Splines during gameplay, setting this up will be fairly easy.

Create a new blueprint actor and create a variable called “SplineActors”. Assign the variable type as your Spline blueprint, and right-click your variable to turn it into an array. Click the eye icon to make it instance-editable.

image

Then, drag and drop this blueprint into your level that contains the splines. On this actor, assign your splines to the array.

Now that your list of splines are saved as a variable, we’ll need some way to send these to your AI. I know there are other ways to communicate between blueprints of different types, but I would recommend a Data Asset here.

Create a new blueprint called a Primary Data Asset.

Inside, the only thing you’ll need to add is your spline array variable.

Then, you’ll need to create a Data Asset as a child of your Primary Data Asset.


Once that asset is created, go back to your manager blueprint. Add a new variable. Set its type to your Primary Data Asset. Click compile to get access to the variable, then set the default value to the child Data Asset that you created.

Now, you can send the spline information over to your data asset on play, since the data asset contains the same variable as the manager. Just make sure you’re setting the variable FROM the data asset here, not the one inside the manager (naming them slightly different things will help you differentiate)

Then, in your AI, you’ll just need to pull the spline list from the data asset. Add your data asset variable to your AI, then you can grab that array directly from it.

I know that was a lot of steps and potentially a lot of new information. Let me know if you run into any trouble.

1 Like

I seriously can not thank you enough! It definitely is a lot of new information as I haven’t had to do this type of thing yet for the game I’ve been working on the past year.

But this is extremely helpful and will help me learn not just how but why.

I sincerely appreciate the time you have taken to give such an in-depth answer and not just a “simple answer.”

I’m using an AI kit from the Marketplace / Fab but the creator is awesome but isn’t always available to help. And it’s vital for some AI to follow the Spline. And in the kit, there is no way to assign Spline paths after they were spawned in. Only if they were already placed in the world.