# GetOwner fail in construction script

**URL:** <https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [September 15, 2014, 9:21am UTC](https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745 "2014-09-15T09:21:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![domzorg](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domzorg/32/906605_2.png) [@domzorg](https://forums.unrealengine.com/u/domzorg)\
**Post date:** [September 15, 2014, 9:21am UTC](https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745/1 "2014-09-15T09:21:08Z")

</div>

I have a blueprint implementing a Character.  
I need to change the Controller class in construction script.  
The GetOwner function always return null in construction script.  
15427-  
How can I get the the object class in the construction script ?

Txs for your help.  
Dom

---

<div class="post-metadata">

**Author:** ![Duncan\_Dam](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Duncan\_Dam](https://forums.unrealengine.com/u/Duncan_Dam)\
**Post date:** [September 15, 2014, 9:35am UTC](https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745/2 "2014-09-15T09:35:24Z")

</div>

From what i know, owner of Actor only determine at run time. For controller class, GameMode blueprint already allow u to change that.

---

<div class="post-metadata">

**Author:** ![domzorg](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domzorg/32/906605_2.png) [@domzorg](https://forums.unrealengine.com/u/domzorg)\
**Post date:** [September 15, 2014, 10:27am UTC](https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745/3 "2014-09-15T10:27:45Z")

</div>

ok, thank you.

Is there a way to change the controller class, coming from a public var defined within the BP, with the construction script. It is an AI, and I would like to be able to set a different AI controller in derived BP.

Dom.

---

<div class="post-metadata">

**Author:** ![Duncan\_Dam](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Duncan\_Dam](https://forums.unrealengine.com/u/Duncan_Dam)\
**Post date:** [September 15, 2014, 10:45am UTC](https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745/4 "2014-09-15T10:45:11Z")

</div>

Anything Pawn that are not control by PlayerController will be control by AIController, the only different between AI Pawns is not controller but BehaviorTree, u can assign different BehaviorTree on each AI Pawn if you want.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [September 15, 2014, 12:03pm UTC](https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745/5 "2014-09-15T12:03:13Z")

</div>

Why you need to change controller class in construct script and why you need owner for that? there actully more raliable way to get contoller using “Get Controller” node

> **[GetController](https://docs.unrealengine.com/5.1/en-US/API/Runtime/Engine/GameFramework/APawn/GetController/)**
>
> Overload list

but as Duncan said things are not initiated yet in constructor, you might alternaticly consider Begin Play event

---

<div class="post-metadata">

**Author:** ![domzorg](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domzorg/32/906605_2.png) [@domzorg](https://forums.unrealengine.com/u/domzorg)\
**Post date:** [September 15, 2014, 1:50pm UTC](https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745/6 "2014-09-15T13:50:43Z")

</div>

After reading all your answers, thank you very much, I think I’m taking the wrong approach.  
I explained what I would like to acheive.

I have a C++ class named AKIACharacter implementing a ACharacter.  
This class is the base for all AI (boot).  
I have also a C++ class named AKIACharacterController implementing a AAIController.

For all boots, I have a BluePrint called BP\_IA based on AKIACharacter. In this BP, on the components side, the character mesh isn’t set. For each bot, I have a specific blueprint based on BP\_IA. In this one, I assign the correct character mesh and its associated animation bp. This works fine.

Now I would like to set behavior to bot. Imagine I have two different bots. Bot1 and Bot2 to simplify. Therefore, I have BP\_Bot1 and BP\_Bot2. Both bp are derived from BP\_IA. If I drag the bots in the level, no problem, they are there and use functionalities implemented in BP\_IA.

As I read, and you explained, I have to use BehaviorTree. Let’s image I make two different behaviour. One is following the player and the other is running from one point to another.  
In the tutorial I’ve seen in unreal web site, we have to create a blueprint controller. And in this blueprint we assign the BehaviorTree. That means, if I understand well, I have to create two BP controller. One based on the following BehaviorTree and the other on the running BehaviorTree.

Therefore I took the approach of creating a public var, based on AIController, in my BP\_IA. Then, for each Boot I will be able to choose, from the editor, the right controller for him. But I might be wrong, and I might create a public var for assigning the BehaviorTree.

What do you think ?

Have a nice day,  
Dom

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [September 15, 2014, 2:01pm UTC](https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745/7 "2014-09-15T14:01:19Z")

</div>

You need to make you ai controller posses the pawn, either by setting AIControllerClass in Pawn/Character defaults

> **[AIControllerClass](https://docs.unrealengine.com/5.1/en-US/API/Runtime/Engine/GameFramework/APawn/AIControllerClass/)**
>
> Default class to use when pawn is controlled by AI.

Or manually spawn controller and make it posses the pawn. Then you can contact controller from pawn via get controller and use behivor tree (thru i never played with it)

---

<div class="post-metadata">

**Author:** ![domzorg](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/domzorg/32/906605_2.png) [@domzorg](https://forums.unrealengine.com/u/domzorg)\
**Post date:** [September 22, 2014, 7:11pm UTC](https://forums.unrealengine.com/t/getowner-fail-in-construction-script/293745/8 "2014-09-22T19:11:40Z")

</div>

Ok. I think I understood. I’ll. try this way.  
In the meantime, I’ve analyzed the ShooterGame sample. They are using the way you described.

Thank you very much for taking time to answer my question.  
Have a nice day,  
D.
