x

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 set transform position of component in code c++

Hi all, another noob question.

I am making a USceneComponent and attaching it to the Mesh in my class inherited from ACharacter

 myLookAtPoint = PCIP.CreateDefaultSubobject<USceneComponent>(this, TEXT("Lookat Point"));
 myLookAtPoint->AttachParent = Mesh;

Next I want to set its default position to be in front of the character face. This is what I tried

 //myLookAtPoint->RelativeLocation.X = -5;
 //myLookAtPoint->RelativeLocation.Y = 5;
 //myLookAtPoint->RelativeLocation.Z = 170;

 //myLookAtPoint->RelativeRotation.Yaw = 90;

It did not work. This is how I checked.

alt text

alt text

As you can see in this view. I have a lookAtPoint made in the blueprint level so that I can adjust the the position. However the myLookAtPoint that I made in code does not have any editable options.

All in all I just want to be able to make components and read their world location in c++ code. However I can't even get the instantiation of components right, why is this so hard?!.

Product Version: Not Selected
Tags:
question3.png (230.5 kB)
question4.png (242.5 kB)
more ▼

asked Nov 15 '14 at 06:58 AM in C++ Programming

avatar image

TinyTeaTree
23 9 10 13

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

1 answer: sort voted first

Hey TinyTeaTree

Don't set the position in code. Attach it to a socket; MyLookAtPoint->AttachTo(Mesh, "look_at_mount");

Compile that, then go in to the mesh and make a socket called "look_at_mount". You can use this tutorial, for example, to see how to do that; https://www.youtube.com/watch?v=-xOoknUDGaE

You can then position the mesh exactly where you want it by hand, in the character BP. I'm not clear on the rest of your question- are you having problems finding the location of this component during run time?

more ▼

answered Nov 15 '14 at 07:37 AM

avatar image

robbiecooper
756 79 60 233

avatar image TinyTeaTree Nov 21 '14 at 07:40 AM

I wrote that, compiled that, and my project died. It can't even get up anymore. Disaster.

avatar image robbiecooper Nov 21 '14 at 08:13 AM

When you changed the code, where there references to it in the BP? Also, just noticed that you're using a scenecomponent.

I have pretty much exactly the same thing, except its a custom static mesh. So, once I have compiled the code and set the socket etc, I go in to the bp and assign a mesh to it;

in the header; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Interaction") TSubobjectPtr FaceSensor;

in the cpp; FaceSensor = PCIP.CreateDefaultSubobject(this, TEXT("FaceSensor")); FaceSensor->AttachTo(Mesh, "face_sensor_mount");

avatar image robbiecooper Nov 21 '14 at 12:46 PM

Yeah its probably bad to attach a scenecomponent to a mesh. Comment out the code, recompile and the project should be back up and running. Then change the component to a static mesh component before recompiling and adding the socket etc. Btw, my code in the previous comment is wrong- the site has deleted the subobject type because its between angle brackets. Let me know how you get on.

(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