-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMyBlueprintFunctionLibrary.cpp
50 lines (40 loc) · 1.57 KB
/
MyBlueprintFunctionLibrary.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyBlueprintFunctionLibrary.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"
#include "Engine/World.h"
bool UMyBlueprintFunctionLibrary::LoadTxt(FString FileNameA, FString& SaveTextA)
{
return FFileHelper::LoadFileToString(SaveTextA, *(FPaths::ProjectDir() + FileNameA));
}
bool UMyBlueprintFunctionLibrary::SaveTxt(FString SaveTextB, FString FileNameB)
{
return FFileHelper::SaveStringToFile(SaveTextB, *(FPaths::ProjectDir() + FileNameB));
}
void UMyBlueprintFunctionLibrary::SpawnFlowersAroundObject(AActor* SpawnAroundObject, TSubclassOf<AActor> FlowerClass, int32 NumFlowers)
{
if (!SpawnAroundObject || !FlowerClass)
{
// Check if the input parameters are valid
return;
}
UWorld* World = SpawnAroundObject->GetWorld();
if (!World)
{
// Ensure we have a valid world
return;
}
FVector SpawnLocation = SpawnAroundObject->GetActorLocation();
FRotator SpawnRotation = FRotator::ZeroRotator;
for (int32 i = 0; i < NumFlowers; ++i)
{
FVector Offset = FVector(FMath::FRandRange(-200.0f, 200.0f), FMath::FRandRange(-200.0f, 200.0f), 0.0f);
FVector FlowerSpawnLocation = SpawnLocation + Offset;
// Spawn the flower
AActor* SpawnedFlower = World->SpawnActor(FlowerClass, &FlowerSpawnLocation, &SpawnRotation);
if (SpawnedFlower)
{
// You can customize the spawned flower's properties here if needed.
}
}
}