AkComponentHelpers.h 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. /*=============================================================================
  16. AkComponentHelpers.h:
  17. =============================================================================*/
  18. #pragma once
  19. #include "Components/SceneComponent.h"
  20. #include "PhysicsEngine/BodySetup.h"
  21. #include "AkInclude.h"
  22. namespace AkComponentHelpers
  23. {
  24. /* Return true if the bodySetup has simple collision */
  25. AKAUDIO_API bool HasSimpleCollisionGeometry(const UBodySetup* bodySetup);
  26. /* Return true if the Point lies within the Primitive component. SphereRadius provides a margin of error for containment.
  27. If OutDistanceToPoint is non-null it will be given the distance from Point to a point on the Primitive component. */
  28. AKAUDIO_API bool EncompassesPoint(UPrimitiveComponent& Primitive, FVector Point, float SphereRadius = 0.f, float* OutDistanceToPoint = nullptr);
  29. /* Return the unreal-units-to-meters ratio being used by this component */
  30. AKAUDIO_API float UnrealUnitsPerMeter(const UActorComponent* component);
  31. /* Return the square of the unreal-units-to-meters ratio being used by this component */
  32. AKAUDIO_API float UnrealUnitsPerSquaredMeter(const UActorComponent* component);
  33. /* Return the cube of the unreal-units-to-meters ratio being used by this component */
  34. AKAUDIO_API float UnrealUnitsPerCubicMeter(const UActorComponent* component);
  35. /* Convenience function for components based on AActor::FindComponentByClass.
  36. Return the first child component of type COMPONENT_TYPE, or nullptr if there are none. */
  37. template<class COMPONENT_TYPE>
  38. AKAUDIO_API COMPONENT_TYPE* GetChildComponentOfType(const USceneComponent& ParentComponent)
  39. {
  40. const TArray<USceneComponent*> parentChildren = ParentComponent.GetAttachChildren();
  41. for (auto* const child : parentChildren)
  42. {
  43. if (child && child->IsA<COMPONENT_TYPE>())
  44. {
  45. return Cast<COMPONENT_TYPE>(child);
  46. }
  47. }
  48. return nullptr;
  49. }
  50. AKAUDIO_API bool IsInGameWorld(const UActorComponent* InComponent);
  51. /**/
  52. AKAUDIO_API void GetPrimitiveTransformAndExtent(const UPrimitiveComponent& Primitive, AkWorldTransform& transform, AkExtent& extent);
  53. AKAUDIO_API void GetPrimitiveUpAndFront(const UPrimitiveComponent& Primitive, AkVector& Up, AkVector& Front);
  54. /* Return true if the movement would reset the child to (0, 0, 0) locally, with respect to the parent position. Return false otherwise.*/
  55. AKAUDIO_API bool DoesMovementRecenterChild(USceneComponent* child, USceneComponent* parent, const FVector& Delta);
  56. /* Log an error for invalid parent type */
  57. AKAUDIO_API void LogAttachmentError(const UActorComponent* child, const UActorComponent* parent, const FString& requiredClassName);
  58. /* Log a warning that parent has no simple geometry, so child will use component bounds */
  59. AKAUDIO_API void LogSimpleGeometryWarning(const UPrimitiveComponent* parent, const UActorComponent* child);
  60. #if WITH_EDITOR
  61. /* IsGameWorldBlueprintComponent() and ShouldDeferBeginPlay() are used to deal with a specific edge case concerning
  62. Blueprint classes: For Blueprint class components, during Super::PostEditChangeProperty(), the component is
  63. replaced with a new instance, and PostEditChangeProperty() is called on the old instance.
  64. In our case this can lead to issues when we update Wwise from PostEditChangeProperty(). For example, duplicate
  65. rooms or geometry could be sent. This check should be used to make sure we don't update Wwise in this scenario.
  66. */
  67. AKAUDIO_API bool IsGameWorldBlueprintComponent(const UActorComponent* InComponent);
  68. /* IsGameWorldBlueprintComponent() and ShouldDeferBeginPlay() are used to deal with a specific edge case concerning
  69. Blueprint classes. For Blueprint class components, during Super::PostEditChangeProperty(), the component is
  70. replaced with a new instance.
  71. The duplicated component instance initially has default values for all UPROPERTY members.
  72. It is only later, after BeginPlay() has been called, that the values from the previous instance's UPROPERTY are
  73. copied to the new instance! So in that case, we need to defer the BeginPlay logic that depends on UPROPERTY values
  74. that have been updated via user interaction, prior to the begin play call.
  75. */
  76. AKAUDIO_API bool ShouldDeferBeginPlay(const UActorComponent* InComponent);
  77. #endif
  78. }