How To Access Object's Components In C++ (Specifically The Rigid Body Component)

I’m still new to the Unreal Engine & C++, & I’m having difficulties understanding how to access an object’s components, specifically the Rigid Body component. I’m coding in C++ a simple first person game where you can pick up, hold & drop objects. I just want to put the picked up object to sleep or disable any physics on it, then reenable the physics when you drop it.

I understand that I can get components by using the function GetComponentByClass() but I don’t understand the syntax for the parameter. I saw this forum post about this issue but I don’t understand how to use this function after reading the answer.

While looking for answers, I found that there’s a UPrimitiveComponent that has a BodyInstance variable that has a single rigid body. It also has a PutInstanceToSleep() & WakeInstance() function which definitely sounds like what I want. How do I use it? What’s the syntax to access it (UPrimitiveComponent::GetBodyInstance(ObjectHeld)->WakeInstance()? or UPrimitiveComponent::GetBodyInstance(ObjectHeld)::WakeInstance()?) I saw this forum post that about this issue but again I don’t understand the answer or the syntax it provides.
Could someone explain to me how to access components of an object in C++?

Function you linking that you “not understand syntax it provides” return something. If you something else then "viod " in decleration that means function return the result and can be used to set variables of type that it return or put in argument of function.:

int32 X = FunctionThatReturnInt32();

FunctionThatHaveInt32Argument(FunctionThatReturnInt32());

So continueing anwser on my other post you linking, look on API refrence of perticialr function:

it return UActorComponent pointer, which is pointer to you component, keep in in variable and then you can call functions, if component is not found it will give you nullptr.

Now there no RigidBodyComponent so i will give you a hint, assuming you want to access USkeletalMeshComponent having rigid bodies (which is also UPrimitiveComponent).

USkeletalMeshComponent* Mesh = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass()));

//Checking if get was successful
if(Mesh) {

        Mesh->DoSomething();

}

If you still don’t understand what this code is doing, you might consider learning more of C++ basics