// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "UObject/ObjectPtr.h" #include "Containers/Array.h" class UObject; class USkeleton; class USkeletalBodySetup; class UPhysicsConstraintTemplate; class UPhysicsAsset; namespace UE::Chaos::RigidAsset { /** * Builder for physics assets * Takes source data for physics assets (bodies, constraints, mesh, skeleton) and creates a UPhysicsAsset (or writes to a target asset) */ class FPhysicsAssetBuilder { public: // Overloads for creating a builder from required data. static FPhysicsAssetBuilder Make(TObjectPtr InTargetSkeleton); static FPhysicsAssetBuilder Make(TObjectPtr InTargetSkeleton, const TArray>& InBodies, const TArray>& InConstraints); // Append a new body to the asset FPhysicsAssetBuilder& Body(TObjectPtr NewBody); // Append a new constraint to the asset FPhysicsAssetBuilder& Joint(TObjectPtr NewJoint); // Apply the provided constraint template to the last pair of bodies in the builder FPhysicsAssetBuilder& JoinLast(TObjectPtr NewJoint); // If not targetting a specific asset, set the path to where the resulting asset will be stored FPhysicsAssetBuilder& Path(FString InDesiredPath); FPhysicsAssetBuilder& Path(TObjectPtr InObjectReferenceForPath); // Set a target asset instead of a path - this asset will be overwritten with new state when Build() is called FPhysicsAssetBuilder& SetTargetAsset(TObjectPtr InAsset); // Finalize the physics asset and apply the builder to it TObjectPtr Build(); private: FPhysicsAssetBuilder(); void CreateNewAsset(); FString DesiredPath; TObjectPtr TargetSkeleton; TArray> Bodies; TArray> Constraints; TObjectPtr TargetAsset; }; }