Access blueprint created component in c++?

Hello community!

I have a character class in c++ derived from ACharacter which declares and defines the functionality of my character. I than derived from my character c++ class and created a character blueprint class which than I set up in my game mode. I don’t like creating components within c++ code so I always do that within the blueprint under add component. So that’s how I added the spring arm and camera to my character. But now I came across one problem using this “comfort” workflow. I don’t know how to access components, like the spring arm and camera, which were created in my character blueprint class, from my character c++ file. I am able to do this in my character blueprint. But I want to manipulate the spring arm from c++ code. Is there a way to access created blueprint components from a c++ class?

Two Solutions

1. Multiple of Same Type

If you anticipate more than one of the same type of component:



//Inside your Actor class

TArray<UStaticMeshComponent*> StaticMeshComps;
****GetComponents****(StaticMeshComps);
for(UStaticMeshComponent* EachSMC : StaticMeshComps)
{
	//perform action on each SMC
       //EachSMC->
}



**2. Only 1 Component Of Its Type**



```


//Inside your Actor class

USpringArmComponent* SAC = ****FindComponentByClass****<USpringArmComponent>();
if(SAC)
{
  //now you can do stuff with the found component, make sure to check if it was found tho!
}


```



Notice how GetComponents takes in an array of a type that you can choose, telling GetComponents what type of component you are looking for! Really neat!

And nothing beats the simplicity of the templated version of FindComponentByClass

**Rama Wiki on Templates in UE4 C++**
https://wiki.unrealengine.com/Templates_in_C%2B%2B

Enjoy!

:)

Rama

It worked thank you! Any documentation on this? I’d like to read something about it instead of copy/paste it.

Edit: Oops. Overread the wiki link, sorry.