The FHitResult has two things called components

The FHitResult has two things called components. They are pointing the same thing; however, they have a different type.
One is returned from function ‘GetComponent’, which belongs to ‘UPrimitiveComponent*.’
The other is a variable of the FHitResult, which belongs to ‘TWeakObjectPtr<UPrimitiveComponent, TWeakObjectPtrBase>.’
What is the second one?
I cannot use the second one because the computer says it cannot be changed into the ‘UPrimitiveComponent*.’

One is a function the other is a variable.

It’s a weak pointer. From the docs

FWeakObjectPtr is a weak pointer to a UObject. It can return nullptr later if the object is garbage collected. It has no impact on if the object is garbage collected or not. It can’t be directly used across a network.

Most often it is used when you explicitly do NOT want to prevent something from being garbage collected.

Because they are different types. You can get the raw pointer from the weak pointer type by calling Get() on it, which is exactly what GetComponent() does.

/** Utility to return the Component that was hit. */
FORCEINLINE UPrimitiveComponent* GetComponent() const
{
    return Component.Get();
}

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms