UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CapsuleComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
8#include "CapsuleComponent.generated.h"
9
11
15UCLASS(ClassGroup="Collision", editinlinenew, hidecategories=(Object,LOD,Lighting,TextureStreaming), meta=(DisplayName="Capsule Collision", BlueprintSpawnableComponent), MinimalAPI)
17{
19
25 UPROPERTY(EditAnywhere, BlueprintReadOnly, export, Category=Shape, meta=(ClampMin="0", UIMin="0"))
26 float CapsuleHalfHeight;
27
32 UPROPERTY(EditAnywhere, BlueprintReadOnly, export, Category=Shape, meta=(ClampMin="0", UIMin="0"))
33 float CapsuleRadius;
34
35#if WITH_EDITORONLY_DATA
36 UPROPERTY()
38#endif
39
40public:
47 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
49
56 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
57 void SetCapsuleRadius(float Radius, bool bUpdateOverlaps=true);
58
65 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
66 void SetCapsuleHalfHeight(float HalfHeight, bool bUpdateOverlaps=true);
67
68 //~ Begin UObject Interface
70#if WITH_EDITORONLY_DATA
71 ENGINE_API virtual void Serialize(FArchive& Ar) override;
72#endif
73#if WITH_EDITOR
74 ENGINE_API virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
75#endif // WITH_EDITOR
76 //~ End UObject Interface
77
78 //~ Begin USceneComponent Interface
79 ENGINE_API virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;
80 ENGINE_API virtual void CalcBoundingCylinder(float& CylinderRadius, float& CylinderHalfHeight) const override;
81 //~ End USceneComponent Interface
82
83 //~ Begin UPrimitiveComponent Interface.
84 ENGINE_API virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
85 ENGINE_API virtual bool IsZeroExtent() const override;
86 ENGINE_API virtual struct FCollisionShape GetCollisionShape(float Inflation = 0.0f) const override;
87 ENGINE_API virtual bool AreSymmetricRotations(const FQuat& A, const FQuat& B, const FVector& Scale3D) const override;
88 //~ End UPrimitiveComponent Interface.
89
90 //~ Begin UShapeComponent Interface
91 ENGINE_API virtual void UpdateBodySetup() override;
92 //~ End UShapeComponent Interface
93
98 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
100
105 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
106 float GetScaledCapsuleHalfHeight() const;
107
113 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
115
122 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
123 void GetScaledCapsuleSize(float& OutRadius, float& OutHalfHeight) const;
124
131 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
133
138 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
139 float GetUnscaledCapsuleRadius() const;
140
145 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
146 float GetUnscaledCapsuleHalfHeight() const;
147
153 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
155
162 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
163 void GetUnscaledCapsuleSize(float& OutRadius, float& OutHalfHeight) const;
164
171 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
173
178 UFUNCTION(BlueprintCallable, Category="Components|Capsule")
179 float GetShapeScale() const;
180
181 // Sets the capsule size without triggering a render or physics update. This is the preferred method when initializing a component in a class constructor.
183 {
184 CapsuleRadius = FMath::Max(0.f, InRadius);
185 CapsuleHalfHeight = FMath::Max3(0.f, InHalfHeight, InRadius);
186 }
187};
188
189
190// ----------------- INLINES ---------------
191
192inline void UCapsuleComponent::SetCapsuleRadius(float Radius, bool bUpdateOverlaps)
193{
195}
196
197inline void UCapsuleComponent::SetCapsuleHalfHeight(float HalfHeight, bool bUpdateOverlaps)
198{
200}
201
202inline float UCapsuleComponent::GetScaledCapsuleRadius() const
203{
204 const FVector& ComponentScale = GetComponentTransform().GetScale3D();
205 return CapsuleRadius * UE_REAL_TO_FLOAT(ComponentScale.X < ComponentScale.Y ? ComponentScale.X : ComponentScale.Y);
206}
207
208inline float UCapsuleComponent::GetScaledCapsuleHalfHeight() const
209{
210 return CapsuleHalfHeight * UE_REAL_TO_FLOAT(GetComponentTransform().GetScale3D().Z);
211}
212
213inline float UCapsuleComponent::GetScaledCapsuleHalfHeight_WithoutHemisphere() const
214{
216}
217
218inline void UCapsuleComponent::GetScaledCapsuleSize(float& OutRadius, float& OutHalfHeight) const
219{
222}
223
224inline void UCapsuleComponent::GetScaledCapsuleSize_WithoutHemisphere(float& OutRadius, float& OutHalfHeightWithoutHemisphere) const
225{
228}
229
230
231inline float UCapsuleComponent::GetUnscaledCapsuleRadius() const
232{
233 return CapsuleRadius;
234}
235
236inline float UCapsuleComponent::GetUnscaledCapsuleHalfHeight() const
237{
238 return CapsuleHalfHeight;
239}
240
241inline float UCapsuleComponent::GetUnscaledCapsuleHalfHeight_WithoutHemisphere() const
242{
243 return CapsuleHalfHeight - CapsuleRadius;
244}
245
246inline void UCapsuleComponent::GetUnscaledCapsuleSize(float& OutRadius, float& OutHalfHeight) const
247{
248 OutRadius = CapsuleRadius;
249 OutHalfHeight = CapsuleHalfHeight;
250}
251
252inline void UCapsuleComponent::GetUnscaledCapsuleSize_WithoutHemisphere(float& OutRadius, float& OutHalfHeightWithoutHemisphere) const
253{
254 OutRadius = CapsuleRadius;
255 OutHalfHeightWithoutHemisphere = CapsuleHalfHeight - CapsuleRadius;
256}
257
258inline float UCapsuleComponent::GetShapeScale() const
259{
260 return GetComponentTransform().GetMinimumAxisScale();
261}
262
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
#define UE_REAL_TO_FLOAT(argument)
Definition LargeWorldCoordinates.h:30
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
@ UpdateBodySetup
Definition BoxComponent.cpp:94
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
Definition Archive.h:1208
Definition PrimitiveSceneProxy.h:296
ENGINE_API FBox CalcBounds(const FVector &P0, const FVector &P1, const FVector &P2, const FVector &P3)
Definition BezierUtilities.cpp:26
FIntermediate3DTransform GetComponentTransform(const UObject *Object)
Definition MovieSceneTracksCustomAccessors.cpp:18
Definition CollisionShape.h:21
float HalfHeight
Definition CollisionShape.h:47
float Radius
Definition CollisionShape.h:41
static constexpr UE_FORCEINLINE_HINT T Max3(const T A, const T B, const T C)
Definition UnrealMathUtility.h:551
Definition UnrealType.h:6865
Definition BoxSphereBounds.h:25
T Y
Definition Vector.h:65
T X
Definition Vector.h:62