관리 메뉴

fatalite

언리얼 MoveComponent (작성중) 본문

게임/Unreal

언리얼 MoveComponent (작성중)

fataliteforu 2023. 8. 29. 18:25

목적

언리얼의 움직임을 담당하는 MoveComponent와 그 파생 클래스들의 관계와 역할을 알아보자.


소스코드 분석

- Update할 Component의 Object Ptr

/**
* The component we move and update.
* If this is null at startup and bAutoRegisterUpdatedComponent is true, the owning Actor's root component will automatically be set as our UpdatedComponent at startup.
* @see bAutoRegisterUpdatedComponent, SetUpdatedComponent(), UpdatedPrimitive
*/
UPROPERTY(BlueprintReadOnly, Transient, DuplicateTransient, Category=MovementComponent)
TObjectPtr<USceneComponent> UpdatedComponent;

- 해당 컴포넌트의 포인터를 이용해서 Move를 업데이트한다.

/**
* Moves our UpdatedComponent by the given Delta, and sets rotation to NewRotation. Respects the plane constraint, if enabled.
* @note This simply calls the virtual MoveUpdatedComponentImpl() which can be overridden to implement custom behavior.
* @note The overload taking rotation as an FQuat is slightly faster than the version using FRotator (which will be converted to an FQuat).
* @note The 'Teleport' flag is currently always treated as 'None' (not teleporting) when used in an active FScopedMovementUpdate.
* @return True if some movement occurred, false if no movement occurred. Result of any impact will be stored in OutHit.
*/
bool MoveUpdatedComponent(const FVector& Delta, const FQuat& NewRotation,    bool bSweep, FHitResult* OutHit = NULL, ETeleportType Teleport = ETeleportType::None);
bool MoveUpdatedComponent(const FVector& Delta, const FRotator& NewRotation, bool bSweep, FHitResult* OutHit = NULL, ETeleportType Teleport = ETeleportType::None);

 

bool USceneComponent::MoveComponentImpl(const FVector& Delta, const FQuat& NewRotation, bool bSweep, FHitResult* OutHit, EMoveComponentFlags MoveFlags, ETeleportType Teleport)
{
	SCOPE_CYCLE_COUNTER(STAT_MoveComponentSceneComponentTime);

	// static things can move before they are registered (e.g. immediately after streaming), but not after.
	if (!IsValid(this) || CheckStaticMobilityAndWarn(SceneComponentStatics::MobilityWarnText))
	{
		if (OutHit)
		{
			*OutHit = FHitResult();
		}
		return false;
	}

	// Fill in optional output param. SceneComponent doesn't sweep, so this is just an empty result.
	if (OutHit)
	{
		*OutHit = FHitResult(1.f);
	}

	ConditionalUpdateComponentToWorld();

	// early out for zero case
	if( Delta.IsZero() )
	{
		// Skip if no vector or rotation.
		if (NewRotation.Equals(GetComponentTransform().GetRotation(), SCENECOMPONENT_QUAT_TOLERANCE))
		{
			return true;
		}
	}

	// just teleport, sweep is supported for PrimitiveComponents. This will update child components as well.
	const bool bMoved = InternalSetWorldLocationAndRotation(GetComponentLocation() + Delta, NewRotation, false, Teleport);

	// Only update overlaps if not deferring updates within a scope
	if (bMoved && !IsDeferringMovementUpdates())
	{
		// need to update overlap detection in case PrimitiveComponents are attached.
		UpdateOverlaps();
	}

	return true;
}

 


 

/** Current transform of the component, relative to the world */
FTransform ComponentToWorld;

 

References

Character Movement Component Architecture | Epic Developer Community (epicgames.com)