Trying to set variables in AIController through the Character Blueprint using Cast

I’m trying to make an NPC that responds to OSC messages by moving to a new location or looking at a new position. I have a BPI_OSCInterface which has an OSCMessage function. I filter those values using an address that is set in the BP_GermWoman before I hit play.

I have the “looking at” working by using a Cast to send a LookAtPos that is calculated in the character BluePrint (BP_GermWoman) to the ABP_GermWoman and using it there. However, I’m having trouble setting variables in the AI Controller because Get AIController is returning None even when I have the AI controller set to AI_GermWoman. The reason I’m trying to set this particular variable is to handle the MovePos calculation logic to the AI controller where it will be sent to a blackboard/behavior tree.

My question is, what am I doing wrong with casting to the AI controller, and am I even going about this the right way? It felt like an interface wouldn’t help me because I specifically want to set the MoveAddress value before the game starts in the BP_GermWoman that is placed in game, instead of the AI_GermWoman that is spawned on game start.

Let me know if anything is unclear!

Here is my BP_GermWoman

Here is my AI_GermWoman

Here are some details of my BP_GermWoman


This is I think the root issue
bp_germwoman_error

Is this single or multiplayer?

If multiplayer perhaps you are trying to access the ai controller from a proxy of the character on the client? (it wouldn’t have the logic, it would just act like a puppet getting commands from the server)

Have you checked if the reference to actor is set? Perhaps it’s null so it’s not possible to get the ai controller? Is the actor actor of type character to get the controller?

Thanks for responding! It’s single-player (at least, I haven’t modifed game mode at all, I just picked the Third Person Map as a default).

I figured actor was always set in the character blueprint (which I made by duplicating the ThirdPersonCharacter blueprint). Would just printing it be the best way to check?

Edit: Also – this character is supposed to just be an NPC, not get possessed or controlled by a controller.

You can use an isValid node to check if the variable is set.

1 Like

Wow ok, looks like it was false – I totally assumed it was always set. What is the proper way to set this variable?

Either expose the variable (eye icon open) and set it once the actor is placed in the world. If the actor is the same character as the internal bp then just get “self” get ai controller.

You can also get actor from class on begin play and set it (not a good practice though because it’s slow) and gets coplex if there are many instances of the actor with that class.

ok – thank you so much – I watched a video on actor components which I realized I hadn’t understood and it made sense. Then I made this change and it is now working, but I wanted to make sure this isn’t the same as the bad practice example you gave-- I am interested in doing it the right way!

Cache what you can up front to variables. Try to do the minimum you can in tick

1 Like

WOW – you are a lifesaver !! Thank you. Good pattern to use everywhere now. :smiley:

Try to avoid tick if you can. If anything can be event driven then let that fire the action (only fires when some action occurs, some variable changes).

Tick can be useful if you need to use some for of interpolation (though you can escape it by using timelines)

1 Like

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