Hi,
I am really new to programming, so the answer is probably obvious but I just can’t figure it out for hours now.
Basically I created a new class deriving from BlueprintFunctionLibrary to have some static functions in it that I can use anywhere. One of the functions would return a TArray with all the actors of the specified class using GetAllActorsOfClass(). However I am having trouble defining the function, no matter what I try it gives me different errors. Here is my code:
MyBlueprintFunctionLibrary.h
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"
/**
*
*/
UCLASS()
class PROTOTYPEGAME_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
TSubclassOf<class AMasterCell> MasterCellClass;
static TArray<AMasterCell> GetAllCells(AGameMode* CurrentGameMode);
};
MyBlueprintFunctionLibrary.cpp
#include "PrototypeGame.h"
#include "MyBlueprintFunctionLibrary.h"
TArray<AMasterCell> UMyBlueprintFunctionLibrary::GetAllCells(AGameMode* CurrentGameMode)
{
TArray<AMasterCell*> ExistingCells;
UGameplayStatics::GetAllActorsOfClass(CurrentGameMode->GetWorld(), MasterCellClass, ExistingCells);
return ExistingCells;
}
This gives me various errors at the GetAllActorsOfCall() line. The parameter MasterCellClass is underlined and the error says:
-a nonstatic member reference must be relative to a specific object.
I can resolve this by declaring MasterCellClass static (however not sure why). But the second error is what I can’t get rid of, ExistingCells is underlined as well saying:
-a reference of type “TArray &” (not const-qualified) cannot be initialized with a value of type “TArray”
Can someone please enlighten me whats wrong? I tried to google the errors but the explanations didn’t really make sense to me probably because of the lack of my experience.
Any help would be really appreciated.
Thanks.