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"

AttachTo and UCapsuleComponent


I run into some issues trying to set the relative location of my camera in c++, the camera would always be placed relative to 0,0,0 in world coordinates. I figured, that this is probably due to the parent of the camera not being set, before the setRelativeLocation took place and decided, to set the parent of my camera myself with the AttachTo() function of USceneComponent.

 FirstPersonCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));

 // Makes sure the UCapsuleComponent is the parent of this Camara
 if (GetCapsuleComponent())

The compiling of this code fails, because it can't convert from UCapsuleComponent* to USceneComponent*, but according to the Unreal Engine 4 Documentation:


Somewhere along the way UCapsuleComponent inherits from USceneComponent, so this should normally work right?

Note: The same code works, if I replace UCapsuleComponent with a USkeletalMeshComponent, by using GetMesh(), but doesn't deliver the desired results. (I will deactivate the mesh and it's children on camera Swap and both cameras have the relative location problem)

Product Version: UE 4.16
more ▼

asked Jul 02 '17 at 02:09 PM in C++ Programming

avatar image

3 1 2 3

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

1 answer: sort voted first

Have you tried this?


If,i am not wrong then,AttachTo() function has been deprecated now. Also,make sure that,you have this header included.

 #include "Components/CapsuleComponent.h"

Maybe,you are getting that conversion error because,you have not included CapsuleComponent.h header?

more ▼

answered Jul 02 '17 at 02:41 PM

avatar image

130 6 7 15

avatar image Jonas_Scholz Jul 02 '17 at 04:00 PM

Thank you for your quick answer!

I indeed forgot the include. (derpy me) I did not know, that missing conversions are an indicator for this.

Have a nice day!

(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