UE5 C++ SplineMesh蓝图函数库实现(小白笔记)

该文章介绍了一个在UE5中使用C++实现的蓝图函数库,用于处理SplineMesh组件。函数库包含了一个名为CanSplineMeshMovAble的方法,该方法根据给定的参数创建并附加SplineMesh到SplineComponent上,同时考虑了不同的变换规则(EMyEnum枚举类型)。此外,还定义了一个静态数组BBB来存储创建的SplineMesh组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UE5 C++ SplineMesh的蓝图函数库实现方法

 UAAABlueprintFunctionLibrary

UAAABlueprintFunctionLibrary.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/SplineComponent.h"
#include "Components/SplineMeshComponent.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "AAABlueprintFunctionLibrary.generated.h"

/**
 * 
 */
UENUM(BlueprintType)
enum class EMyEnum:uint8
{
		KeepRelativeTransform UMETA(DisplayName = "KeepRelativeTransform"),
		KeepWorldTransform UMETA(DisplayName = "KeepWorldTransform"),
};

UCLASS()
class SPLINECPP_API UAAABlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintCallable,Category = "Move SplineMesh")
	static void CanSplineMeshMovAble(USplineComponent* Spline01,USplineComponent* Spline02,UStaticMesh* SplineStaticMesh,ESplineMeshAxis::Type ForwardAxis,ESplineCoordinateSpace::Type Scapse,bool Movable,EMyEnum MyEnumParam);

	static void abc();
private:
	static TArray<USplineMeshComponent*> BBB;
};

UAAABlueprintFunctionLibrary.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "AAABlueprintFunctionLibrary.h"

#include <filesystem>
TArray<USplineMeshComponent*> UAAABlueprintFunctionLibrary::BBB;

void UAAABlueprintFunctionLibrary::CanSplineMeshMovAble(USplineComponent* Spline01, USplineComponent* Spline02,
                                                        UStaticMesh* SplineStaticMesh, ESplineMeshAxis::Type ForwardAxis, ESplineCoordinateSpace::Type Scapse,bool Movable,EMyEnum MyEnumParam)
{
	abc();
	if (!Spline01)
	{
		return;
	}

	Spline01->RegisterComponent();
	int32 Point = Spline01->GetNumberOfSplinePoints();

	if (Point<2)
	{
		return;
	}
	
	for (int32 i = 0; i<Point-1; i++)
	{
		FVector startlocation,startTangent,Endlocation,EndTangent;
		Spline01->GetLocationAndTangentAtSplinePoint(i,startlocation,startTangent,Scapse);
		Spline01->GetLocationAndTangentAtSplinePoint(i+1,Endlocation,EndTangent,Scapse);

		USplineMeshComponent* SplineMesh = NewObject<USplineMeshComponent>(Spline01);
		SplineMesh->SetMobility(EComponentMobility::Movable);
		SplineMesh->SetStaticMesh(SplineStaticMesh);
		SplineMesh->SetForwardAxis(ForwardAxis);

		SplineMesh->SetStartAndEnd(startlocation,startTangent,Endlocation,EndTangent);
		switch (MyEnumParam)
		{
		case EMyEnum::KeepRelativeTransform:
			SplineMesh->AttachToComponent(Spline01,FAttachmentTransformRules::KeepRelativeTransform);
			break;
		case EMyEnum::KeepWorldTransform:
			SplineMesh->AttachToComponent(Spline01,FAttachmentTransformRules::KeepWorldTransform);
			break;
			default:
				break;
		}
		SplineMesh->RegisterComponent();

		BBB.Add(SplineMesh);
		
		
	}
}

void UAAABlueprintFunctionLibrary::abc()
{
	//GEngine->AddOnScreenDebugMessage(-1,0.5f,FColor::Red,FString::Printf("%s"),BBB.GetTypeSize(),true);
	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我救我自己

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值