Get owner node?

hello.all.
if my actor spawned a actor using spawn actor from class node,and pass in self to the owner pin.

the spawned actor can easily use get owner node to reach the actor who spawned it.

but if my actor spawned a pawn.the pawn can’t get the actor who spawned it.instead,it gets the controller.
how do I prevent that?I need the actor.
or actors can’t own a pawn?
how does a pawn get the actor who spawned it then?
thank you !

I don’t really know why the owner returns the controller, but anyway you can create your own actor type variable that contains the one that spawned.

1 Like

thank you sir!
I actually want to practice decoupling.
now I use basic actor type class variable to spawn the pawn.so I canceled the exposed on spawn option.
I want to have the spawned pawn to send massage to the owner to get some initial data.
but it returns controller that is annoying :joy:

Pawns, in general, are meant to be possessed by controllers. It’s what differentiates them from actors. @baobao4435 , if you want to change it, I believe you’d have to do it manually in C++.

I haven’t encountered this issue, so I cannot say for certain.

But is it possible to either:

  1. Swap the actor for the pawn after spawning?
  2. Have the actor be a child of the pawn, and use the actor’s information for the pawn?

I don’t yet know how what you’re doing works, so it’s guessing on my part.

1 Like

thank you!
I hope I can avoid to touch CPP. :joy: .



it’s like my owner actor got thrown away.

1 Like

Nah, Bao, C++ is great once you get used to it… ← is a lie that people who program in C++ tell you to get more people in their community to help them.

I’m looking at your blueprints, and it doesn’t look like the spawned actor has time to be reassigned an owner, because you’ve attached an EVENT_BEGIN_PLAY node to the pawn’s code.

Maybe create a CUSTOM EVENT that fires the code below after the pawn is spawned?

1 Like

I’ll try to learn CPP in the future if I have time. now there’s so many modules I haven’t yet touched.material.Niagara,etc…actually I’m still a newbie :grin: .because I am not so sensitive about performance so I think CPP should put very last place…

I tried as you say.I put a delay node in the beginplay.and it still returns controller.

I begin to think it’s probably that I can’t get actor owner from a pawn…I might need to make a custom event for the pawn specifically to do initial stuff.
and have the actor who spawned it to call the pawns initial event.

But I don’t really like the method…however if there’s no other way to get the owner I’ll probably have to do it.

1 Like

HA! You mean like extra time left over?

I’m joking, but seriously, if you’re looking to be a solo-dev, trying to use C++ right now, if you don’t already, is VERY difficult to do, because you’d have to basically stop everything for weeks to learn it.

Anyway:

I think this is true, because Pawns are Actors with controllers. You’d have to create your own C++ class.

Hopefully someone else in the forums knows a better solution than mine or yours.

1 Like

When possessed the pawn class auomatically overwrites the owner value with a pointer to the controller.

From Pawn.cpp:

2 Likes

You have 2 options
Right after spawning you can call functions, these functions are called even before begin play.
If you don’t want to cast, use an interface.


In this example I use spawn AI but it works the same with spawn actor

Another option is to create a base class that contains the variables and is the one that you connect to the spawn node casting.
Then you will see that the exposes variables are there, but the class you send can already be any child, the result of the spawn will be the class you sent

1 Like

@DomusLudus thank you, i was thinking about this too

however the interface is called after the pawn’s beginplay on my side…i’ll have to give up using the pawn’s beginplay.and use the interface call as its “beginplay”.
i kind of don’t really like do it like this.because it looks like that others are doing the pawn’s own job.
however i’ll have to do it this way probably.

@pezzott1 thank you,its a solid information,but i opened the pawn class in VS.i see it only has 500+ lines.yours at line 626? how do i find it?if i found it,can i simply delete the Setowner line and i won’t cause issues?

GetOwner is mostly used for replication in Multiplayer as it returns the NetOwner. If you change this then replication won’t work as expected on the pawn.

What you are looking for is GetOuter which returns the object this recides in. It is not exposed to Blueprint though and you should not change this unless you know what you are doing.

The outer is what keeps an object alive and it will be garbage collected if the outer gets destroyed.

I suggest you use the Instigator instead of the owner.

2 Likes

instigator only accepts a pawn…

I forgot about that. I guess you will have to find another way then.

1 Like

thank you anyways

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