# How do I find a component by name?

**URL:** <https://forums.unrealengine.com/t/how-do-i-find-a-component-by-name/288333>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 16, 2014, 6:54am UTC](https://forums.unrealengine.com/t/how-do-i-find-a-component-by-name/288333 "2014-07-16T06:54:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_f6530a3e1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f6530a3e1](https://forums.unrealengine.com/u/anonymous_user_f6530a3e1)\
**Post date:** [July 16, 2014, 6:54am UTC](https://forums.unrealengine.com/t/how-do-i-find-a-component-by-name/288333/1 "2014-07-16T06:54:42Z")

</div>

I want to define a position within my Pawn actor for something to float in front of the actor. It doesn’t have to be a rigid attachment like a socket, so I don’t mind if it is slightly off every frame.

Firstly I can’t find any function such as GetComponentByName()

Secondly, i’ve tried using some of the components that let you transform and rename them, such as an ArrowComponent or a SceneComponent, and changing their name. I can’t work out how to retrieve that name in code! I’ve tried GetName() but this doesn’t match the name I’ve edited, and looking through the header files I can’t find the variable that corresponds to the set name.

Can anyone help? Am I doing this wrong?

**EDIT:** It seems that there is no inbuilt way to do this, and the only way to do it is to create your own components or to retain a link to the component when you create it.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [July 16, 2014, 7:51am UTC](https://forums.unrealengine.com/t/how-do-i-find-a-component-by-name/288333/2 "2014-07-16T07:51:04Z")

</div>

you can make your own component, and give it the name variable you want,

**wiki tutorial: Custom BP-friendly UObject Components**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

then you can find it by doing this

```
for(TObjectIterator<UYourCompClass> Itr; Itr; ++Itr)
{
   if(Itr->YourStringVariableName = "YourName")
  {
     //do stuff!
     return;

  }
}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f6530a3e1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f6530a3e1](https://forums.unrealengine.com/u/anonymous_user_f6530a3e1)\
**Post date:** [July 16, 2014, 8:14am UTC](https://forums.unrealengine.com/t/how-do-i-find-a-component-by-name/288333/3 "2014-07-16T08:14:23Z")

</div>

Thanks , I ended up adding a new component in C++ which had a set name, and then just referencing that.

I did run into a problem adding a new component (in code) to a blueprinted objected I had already created - because the new component didn’t show up. I believe this is a known issue and has been fixed (?) in later builds. Anyway, If anyone else comes across this I ended up having to re-create my blueprint and manually transfer all of the old values I had to make the component show up.

---

<div class="post-metadata">

**Author:** ![Roi\_Danton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Roi\_Danton](https://forums.unrealengine.com/u/Roi_Danton)\
**Post date:** [January 25, 2018, 8:22pm UTC](https://forums.unrealengine.com/t/how-do-i-find-a-component-by-name/288333/4 "2018-01-25T20:22:37Z")

</div>

When I want to find a component of a certain actor instance, is TObjectIterator the right choice? Doesn’t it catch all objects of UYourCompClass of all actor instances?
