[C++] How to get/pass reference to bluprint's component
How to get a reference/pointer to some bluprint's added component? I already now that when I put this:
And then in class constructor put this:
The new component is being created and it can't even be deleted from the blueprint editor - which is somehow nice. But this is an easy one. The question is, how to pass already made component in the editor to the c++ code. Especially not simple one.
Let's say, I've nested another blueprint in that blueprint, and I want to have and access to it in my code. So I need to grab it's reference somehow and pass it to c++ script.
Dealing with it in blueprint script is super easy - drag'n'drop and you can do whatever you want on your nested Actor. How to do it in code?
Thanks in advance!
asked Oct 28 '16 at 10:52 AM in C++ Programming
You can use a handy utility:
To get the Path: Right click on a blueprint, and select
answered Oct 28 '16 at 12:00 PM
You can use the GetComponents() function to get an array of all of the components attached to the calling actor. You can then use a for loop to cast each component to the type you're looking for to find the specific component necessary. If your components are listed with tags, you can use the GetComponetsByTag() function to get the components from the given class that also use the given tag. For more information on how to get the actor's components, you can check the Actor class documentation (https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/index.html ).
answered Nov 02 '16 at 02:23 PM
I'm so glad I found this thread. I'm used to unity c# where you can simply get a component reference by typing one simple line of code and get the explicit reference to the exact component you set up in the inspector before that. I'm blown away that unreal doesn't have a similar feature. Having to get all components with tag just to find one of the components attached to the same actor just seems mediocre at best.
I guess I'll have to venture back into the Stone Age to access a simple component on my actor.
answered Jul 11 '17 at 07:58 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here