Why doesn't BP Spawn Node set correct AI Controller subclass?

The Spawn Actor node do not correctly set the AI Controller to the class specified in the Character Blueprint. The AI Controller Subclass is also a Blueprint.

This is related to the question I asked regarding the Spawn AI Node, not doing the same thing.

Casts always fail.

Dragging from the output pin of the Spawn Actor node only gives option for get AI Controller Class, but it does not have the variables or functions from the AIController Subclass Blueprint that is set on the Character.’

If a pawn is placed directly in a level, it will create its Default Controller class when the level begins. However, Pawns that are spawned into the level later don’t spawn their controller by default. You need to call “SpawnDefaultController” on the pawn after you spawn it. Here’s an example similar to your blueprint:

1 Like

Awesome, thanks for the answer.

Should I make a request, for a check box to be added to the SpawnActor node that it spans the default controller? This wasn’t obvious behavior

Once we fix the bug preventing the Spawn AI blueprint node from creating the correct default controller, I’d probably recommend using that node instead. (The solution above is a perfectly valid solution though.)

I doubt that SpawnActor will have special properties added specifically for spawning Pawns, especially when SpawnAI can handle that situation well. You can certainly ask for the option though, or ask on the forums why spawned pawns behave differently from pre-placed pawns. (I don’t actually know the answer as to why spawned pawns don’t automatically create their controller but placed pawns do. I presume there’s some reason for it, but it can’t hurt to ask!)

How do you attach a BehaviorTree and BlackBoard to controller spawned with the SpawnActor node?

Edit: I’m not sure how to spawn the BT, spawn Actor won’t accept it.

To run the Behavior Tree and Blackboard:

In your pawn blueprint, get the Controller, cast it to AI Controller, and then call RunBehaviorTree (just once, this is an initialization step).

The behavior tree asset you specify in RunBehaviorTree needs to specify a Blackboard asset in its root node. That blackboard will automatically be loaded and used.

Got that to work, thank you.

Ran into this issue myself, and thought I’d update on the current state of things. As mentioned, you can now call “Spawn AI from Class”. It seems like you ought to be able to use “Spawn Actor from class”, but the AI Controller still won’t get created for whatever reason, which is pretty confusing. It’s extra confusing that it works correctly when the blueprint is placed directly into the level. Maybe in the future Spawn Actor will be smart enough to include AI, but for now they need some special handling.

16549-aispawn.png

Thank you for noticing this. It has saved me a lot of time.

Check this if you use C++
https://answers.unrealengine.com/questions/4319/questioncai-spawning.html