Here’s me spawning my BP_Gun object and attaching it to BP_Ship’s mesh:
How can I get BP_Ship from inside BP_Gun’s event graph? Some sort of GetParent node? The only ones I see are for getting USceneComponent objects the current BP is attached to, not the actor?
When you attach a component, make sure you attach the ROOT component to the target. In this case ‘Skeletal Mesh’ must be the ROOT. Is this how you did it? You better use ‘Get Root Component’ node for this.
Once you’ve made sure of that, you can use ‘Get Owner’ node on the root component of your gun to get a reference to the Actor it is attached to
Skeletal Mesh is definitely the root of the BP_Ship.
How do I get this BP_Ship inside the BP_Gun, though? Can I get the component an actor is attached to, or something else?
Yes I think there is a node called ‘Get Owner’ to do this. Inside your Gun BP, get a reference to the Root node (the skeletal mesh) and call ‘Get Owner’ on that, it should return the BP_Ship actor
Any set up I try along those lines gives me a None return value. All casts fail. I don’t think I mentioned this, but BP_Gun is based on an Actor, and BP_Ship is based on a Pawn. The BP_Gun is AttachTo-ed the BP_Ship pawn at a certain socket. Using ‘GetOwner’ owner can seem to run on to infinity, and if I want to cast it, I can only do so to my other Actor BPs, not to any Pawn-based BPs.
I tried this with ‘Attach Actor to Actor’ node. You are right, even after the attachment, the ‘Get Owner’ node called on the root component of the attached actor (the Gun), returns BP_Gun instead of the Pawn.
Not sure if this is intended or a bug. I will ask around
Ok, I have asked this in the forums and Mark Audy has given us a possible solution.
You can use GetRootNode → GetAttachParent → GetOwner to get the BP_Ship from the Gun blueprint. Note that I used ‘Attach Actor to Actor’ node instead of ‘Attach Actor to Component’. But I dont think it will matter.
Pease try this and let me know if tis works
So doing this results in a successful cast, but trying to access the BP_Ship’s variables doesn’t work. Complains about a local scope issue, even though I know the BP, and the class it’s based on, have this variable.
P.S. BP_Ship is actually BP_Fighter in my setup - I named it wrong and I don’t want you to think I’m trying to call to a different file
It’s actually a variable in C++ I exposed via the UPROPERTY macro, and it’s updated in C++ too.
I wonder if there’s a way to get the property to be public in my class for blueprints, but not public for code? I don’t want any old C++ file able to change it.
Are you 100% it’s the public/private/protected issue? The blueprint system shouldn’t even let me access these variables if they’re private?
Those variables you are trying to access must be made public in the BP_Fighter blueprint. However it is better to define a function inside BP_Fighter, whcih accepts new values for these variables as iputs and sets them up correctly. Then call this function from the other bluepritn with the actual values.
Well you did not say anythig about C++ code until now. I thought those variable were created inside Blueprint editor itself.
Heres what you can check:
See if those variable are accessible inside the BP_FIghter blueprint. If they are not, first get them accessible there.
Or you could try the other method, write the function to set these variables and expose that function. Call it from the BP_Gun blueprint
I ended up putting some public UFUNCTION-ed Get methods in my C++ class. Worked a charm, especially combined with your stack of nodes to get to the BP_Fighter object. Thanks!
if the issue is solved, please mark this thread as solved…
I can’t figure out how to mark any of your posts as the answer, or this thread as solved
Every answers has a ‘tick mark’ to its left. Click one the one that belongs to the right answer.
PS: I have done it for you this time.