How do I properly use the get owner node?

I see a get owner node…I’ve tried using it to cast to a class BP and use it or use variables of it but I can never get anything to cast correctly. …is there something special about the get owner node?? Or a certain way it had to be used?

Thanks everyone!

Owner is varable which should hold refrence to actor that owns this actor or actor that this actor belongs to. For example character actor is owner of a weapon that he holds. In C++ you need to set owner manually when you spawning, im not sure about blueprint it would not be suppriced if owner therebis set automaticly to actor that spawns the actor, if not then you will need to set owner first :wink:

I’m not really sure I understand exactly…When u cast To characters that are spawned how do you get that to work?? I’m not good at casting…I was hoping that the get owner node would help with that problem…

Owner can be anything and in order to cast you need to expect what it is. If you set character as owner you cast to that character, if cast fails the chain of actions is breaked and flow ends.

Again owner is just a premade varable, you can set anything as owner and you cast to class you except it to be, the one you set as a owner

If you are using getOwner to find out the top-level Actor that owns this comonent, its better to use ‘GetRootComponent → GetAttachParent → GetOwner’. The reason is if you attatch an Actor to a component of anotehr Actor, simply calling GetOwner will return the wrong Actor (it will give you the old Actor not the new parent).

Once you get the Actor, you can cast it to Pawn, Character… depedning on your logic.

Ok that helps a little…
Basically it’s my projectile. Being spawned from the my character BP. I have a pickup that slows down time. But I set custom time dilation for the character so it isn’t affected and I need the projectile to not be affected ad well…thus the reason I needed to cast to it inside the pickup BP to set custom time to it…is there a certain way I can do that?

Let me understand… so you want to get a reference to your projectile from the Pickup’s blueprint?

I dont see where GetOwner comes into play here. What you can do is when you spawn a projectile, adjust its time dilation to what the value is currently for your player. To do this you dont have to use any Get Owner nodes. The downside is projectiles that are already spwned will not get the Player’s custom time-dilation.

I dont see how you can get all the projectiles spawned by the Player inside Pickup’s blueprint unless your Player maintains an array that keeps track of all your projectiles to do that. OR you could colelct all Projectiles in your level and check who spawed it and adjust their time dilation values accordingly.

I would probably define a Blueprint interface for these proejctiles and define a function to change the time dilation. Then I will collect all Projectiles with this interface and call this function from Pickup BP

Not only components has Owner, but all Actors do, and can be used to track whosor what weapon fired that projectile… maybe thats what he wants ; p

still he needs to go through all the projectiles in the scene, doesn’t he?
I think setting custom dilation at spawn time is the easiest method. But maybe that doest fit his requirement.

I’m still not sure exactly what i should do here…its definitely a halt but thank you for your help guys. …Like I said the character and controller aren’t affected by the global dilation because of the custom dilation…and it’s easy to pull from them…get player controller or character…drag a wire…barn. custom time dilation…I wish it was that easy with the projectile BP…:frowning:

@AttemptD:
Did you try to set the time dilation when you emit the projectile? I dont see why you could not. You have all the Actos there.the Projectile, The Weapon, Controller and Pawn.
Just set the time-dilation value to the spawned projectile there.

I will try and see if I can setup a blueprint myself when I get some free time.

All of these blueprints are in the Pickup class BP, it’s the item that when the character touches it slows down the global time and then changes it back after 5 seconds. But as it sets the global time dialation I pull the get player character and controller node, drag a wire, ad type custom time dialation, which is a float variable i assume. I set those accordingly to adjust to the math of the global and tadaaaa…but the projectile is being spawned by the character, and it’s its own BP…I was trying to cast to it to set it’s custom time…but don’t know how…I’m lost.

Ok so you want to set time dilation to projectiles fired by the charcter when you touch the pickup?
Ok,
So all you need is to find all the projectiles fired in the world. Why dont you try the ‘Get by Class’ node and set it to find projectiles? Later do a foreach and try casting them to Projectiles. Call the GetOwner node and cast the output to your Charcter (or Wepaon based on how you are setting the owner).

I will probably get some free time today evening and I will test it out myself.

@AttemptD
I checked this myself. And it looks like getting the Owner Charcter from a Projectile is pretty difficult. The Get Owner node returns only the Projectile object itself.

So I added an additional variable within the projectile BP. This variable will hold a reference to the Character that spawned it. I set this variable right after ‘Spawn Actor’ node. Later I iterate through all projectiles in the world and use this variable to get a reference to the Character and set the time dilation equal to that of the Character.

Not exactly what you need, but seems to do the trick.

I guess that sort of works though…How exactly did you pull that off?? in blueprints that is?

Here is the detailed description of how I achived it:

We need 4 Blueprints for this:

  1. A Charcter/Pawn blueprint - This will act as the player charcter.

  2. BP_PlayerProjectileBase - This will act as the base class for any projectile classes to be fired by the charcter. Most of the logic goes here

  3. BP_Pickup - A BP extended from Actor which will allow the Player to slow down time.

  4. BP_Projectile - Extended from BP_PlayerProjectileBase. There is nothing fancy in here.

Working:

BP_PlayerProjectileBase:
In the Components we have an Arrow comp as root. This is a hack to make sure there is a primitive component at the root.
We have added a custom Actor varible inside BP_PlayerProjectileBase called ‘Projectile Owner’. This variable holds a reference to the Actor who spawned the projectile.
We also have custom function 'Set Projectile Owner. This is where most of the logic is. This function will be called from outside after projectile is spawned with the Owner actor as input.
We try to cast the owner to MyCharacter and if it succeeds, binds an event to ‘OnCustomTimeDilationChanged’ (defined in MyCharacter which is coming up). Also we try to unbind any previously bound events before hand. Then we set this Actor as the new value of ‘Projectile Owner’ variable.
The function ‘OnOwnerTimeDilationChanged’. This function accepts a float (Time Dilation). We simply set the Custom Time Dilation for the proejectile to the incoming value.

10639-bp_projectilebase_on_owner_tdc.jpg

…Continuation…

BP_MyCharcter:
This is extened from Character. We have a custom event dispatcher named ‘OnCustomTimeDilationChanged’. This will be called (manually) whenever we change the custom time dilation.
The Fire event will simply spawn a Projectile (extened from BP_PlayerProjectileBase) and call ‘Set Proectile Owner’ with ‘self’ as owner.

][1]

BP_Pickup:
Within the ‘Begin Overlap’ event, we set the gloal time dilation to 0.2 and set MyCharcter’s custom dilation to 5 (to compoensate). Then we call the dispacher (this will notify all projectiles fired by this charcter to change their time dilation)
In the ‘End Overlap’ event, we reset Global and Custom time dilation back to 1.

BP_Projectile:
A capsule component is atatched to Arrow for collsions. Billboard is used for Visual purpose.
A projectile movement compoenent with intial speed 500 and gravity scale 0.

This is excellent! ! Thank you do much for pulling this off for me. I’m looking over it now and I should be able to get this to work. Thank you again for all if your help! !! :slight_smile:

Hi . This is old I know. Can this be used to get the owner of an actor variable? Say I have an actor weapon variable (not component) in my character class, if I use getOwner will my character’s actor reference be returned? Or should I use 'GetRootComponent → GetAttachParent → GetOwner` instead? Thank you.

1 Like