Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I find a component by name?

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.

Product Version: Not Selected
more ▼

asked Jul 16 '14 at 06:54 AM in C++ Programming

avatar image

195 18 122 34

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

wiki tutorial: Custom BP-friendly UObject Components


then you can find it by doing this

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

more ▼

answered Jul 16 '14 at 07:51 AM

avatar image

10.6k 446 346 1088

avatar image AusPaco Jul 16 '14 at 08:14 AM

Thanks Rama, 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.

avatar image Roi Danton Jan 25 '18 at 08:22 PM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question