Try to get the right rotation when attach a actor to an

I want to attach a weel to a car frame (it is a toy car), using my vr controllers.
When I attach the wheel to the car frame the position is ok but the rotation is of.
The rotation of the wheel is dependent on the position of the car frame.
Is there a calculation that i can do to get the right rotation for the wheel ?

I’d suggest adding Arrow components where you’d like the wheels to be attached (with the correct rotation) and then attach the wheels to the arrows.

Or sockets. And then Arrows to see what’s going on.


Generally speaking, if something is not attached, you use world rotation. If it is attached, you use relative rotation (local). There are also helpful nodes to (inverse) transforms from one dimension to another.

Sockets certainly sound like the way to go, I’ve posted a link below to an unreal document on setting up sockets on Static Mesh, you can easily find a similar resource for skeletal mesh if you can’t. The beauty of Sockets is that anything that you attach to the socket will take on the Location, Rotation, and Scale of the socket.

If you don’t see the sockets, go to “Windows” tab and click on “Socket manager”, then in the bottom right corner of the editor you should be able to see the socket manager, from here you can add a new socket by hitting the green button. For your preview mesh you are going to want to select your where. From here use the details panel to adjust you socket to best fit the wheel and you’re done. Then when you attach you wheel to the car just make sure to include the socket name just as you set it up. (Picture below for Socket manager location)

ie. in C++

MyWheel -> AttachToActor(MyCar, AttachmentRules,TEXT("SocketName"));

I hope this helps. Link to unreal docs below:

[Setting Up and Using Sockets With Static Meshes | Unreal Engine Documentation][1]

Ok that worked . I should tought about that ,to rotate the scene or arrow component.I know about sockets but i wanted to try it first this way.
I have an other question.
I created a scene component whit a function and interface to checkt if the actor is a wheel or somthing else that can be attached to it… For easy to reuse in other actors an for other parts.
To check if the wheel is a wheel i use an enum.
But i think i am going to need a lot of different enums if i have other parts or different types of wheels.
So i was thinking about using a list of classes to check wich parts can be attached.to .
Is this a better way ,or is there an other way to check if that wheel or other part can be attached to it.

I would recommend using tags, there is a node, ActorHasTag, that returns a boolean value based on whether and actor or component has tag. This way you just put a tag on each actor you want to be able to attach to your truck and the truck check to make sure the actor that has that tag. You can add tags to both Actors and Components and there is a ComponentHasTag node as well so make sure you add the tag at the right level.

You can either add tags through code or directly through blueprint, just go to the details panel and search for tags. One last note, be sure to name the tags something easy to spell and remember as the input tag you use for these nodes must match exactly and they are case sensitive.

If this answers you’re question, please remember to come back to accept it and markyour question as resolved, I hope it all works out for your and best of luck!

I posted a link to the unreal docs on the node here: https://docs.unrealengine.com/en-US/BlueprintAPI/Utilities/ActorHasTag/index.html

In C++ it looks like this:

 //My Actor Class cpp
    //In the constructor
    AMyActorClass::AMyActorClass(){
    
       Tags.Add(TEXT("MyTag"));
    }
    
    //My truck .cpp
    void MyTruck::AttachToWheel(AActor* ActorToAttach){
        if(ActorToAttach->ActorHasTag(TEXT("MyTag"))
        {
              //Attach actor to wheel socket    
        }
      else{
            //Don't attach actor to wheel socket
      }
    }