I created maze generation lib, but when I try to compile, it returns error:
CompilerResultsLog: Error: D:\Home\Volodya\Projects\Games\UE4\TestingSomething\Something\Source\Something\Private\MazeLib.cpp(17) : error C2352: 'UObject::GetWorld': illegal call of non-static member function
CompilerResultsLog: Error: C:\Program Files\Epic Games\UE_4.18\Engine\Source\Runtime\CoreUObject\Public\UObject/Object.h(473) : note: see declaration of 'UObject::GetWorld'
CompilerResultsLog: Error: D:\Home\Volodya\Projects\Games\UE4\TestingSomething\Something\Source\Something\Private\MazeLib.cpp(17) : error C2227: left of '->SpawnActor' must point to class/struct/union/generic type
CompilerResultsLog: Error: D:\Home\Volodya\Projects\Games\UE4\TestingSomething\Something\Source\Something\Private\MazeLib.cpp(17) : error C2227: left of '->GetAuthoritativeClass' must point to class/struct/union/generic type
CompilerResultsLog: ERROR: UBT ERROR: Failed to produce item: D:\Home\Volodya\Projects\Games\UE4\TestingSomething\Something\Binaries\Win64\UE4Editor-Something-5058.dll
My spawnMaze function in cpp file:
void UMazeLib::spawnMaze(int size) {
bool** maze = generateMaze(size);
for (int h = 0; h < size; h++)
{
maze[h] = new bool[size];
for (int w = 0; w < size; w++)
{
const FVector* position = new FVector(10 * h, 10 * w, 0);
GetWorld()->SpawnActor(wallClass->GetAuthoritativeClass(), position);
}
}
}
and my .h file:
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Wall.h"
#include "MazeLib.generated.h"
/**
*
*/
UCLASS()
class SOMETHING_API UMazeLib : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Something")
static void spawnWall(FTransform str);
UFUNCTION(BlueprintCallable, Category = "Maze")
static void spawnMaze(int size);
UPROPERTY(BlueprintReadWrite, EditAnywhere)
TSubclassOf<class AWall> wallClass;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UWorld* world = GetWorld();
private:
static bool** generateMaze(int size);
};