Can I transfer reference to object from pawn to AI Controller or task? How?

Hello.

I’m working with bunch of friend on Third Person Shooter and I’m struggling with one thing.

Using behaviour tree and Environmental Queries I managed to have enemies hiding from me and after couple of seconds walking out of cover. So now I want to make them shoot. My friend made blueprint of weapon that is spawned to socket of character, but if I spawn it to character I can’t access it from neither AI controller or task_blueprint.

This is how it’s solved in Player controlled character:
http://i.imgur.com/tmPRCnF.png

Can I somehow access Main Gun from AI Controller or task Blueprint that is attached to pawn having this object?

You can access the possessed Pawn from the AIController by using the GetControlledPawn node. You’ll need to cast the returned Pawn to the enemy Blueprint and from there you should be able to get your weapon.

Alternatively, you could add a reference to the weapon to the AIController and update it whenever the weapon changes (or in character BeginPlay if it never changes). To get the possessing controller of a given pawn use the GetController node and cast the result to your AIController.

In both cases, don’t forget to check if the returned object isValid in case something went wrong or the cast failed.