# "UGameplayStatics::GetAllActorsOfClass" is inaccessible

**URL:** <https://forums.unrealengine.com/t/ugameplaystatics-getallactorsofclass-is-inaccessible/437723>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [November 16, 2018, 2:18am UTC](https://forums.unrealengine.com/t/ugameplaystatics-getallactorsofclass-is-inaccessible/437723 "2018-11-16T02:18:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JedediahTheWolf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jedediahthewolf/32/1161208_2.png) [@JedediahTheWolf](https://forums.unrealengine.com/u/JedediahTheWolf)\
**Post date:** [November 16, 2018, 2:18am UTC](https://forums.unrealengine.com/t/ugameplaystatics-getallactorsofclass-is-inaccessible/437723/1 "2018-11-16T02:18:24Z")

</div>

Hey guys! i’m following a udemy tutorial series and have been doing fairly well so far until I can into this error:

Error (active) E0265 function “UGameplayStatics::GetAllActorsOfClass” (declared at line 83 of “d:\Epic\UE\_4.20\Engine\Source\Runtime\Engine\Classes\Kismet\GameplayStatics.h”) is inaccessible FPSGame d:\Game Development\Projects\StealthGame\Source\FPSGame\Private\FPSGameMode.cpp 29

I’m not entirely sure how to fix it despite several tries and many hours of frustration!  
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

```
#include "FPSGameMode.h"
#include "FPSHUD.h"
#include "FPSCharacter.h"
#include "UObject/ConstructorHelpers.h"
#include "Engine/World.h"
#include "Kismet/GameplayStatics.h"

AFPSGameMode::AFPSGameMode()
{
	// set default pawn class to our Blueprinted character
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnClassFinder(TEXT("/Game/Blueprints/BP_Player"));
	DefaultPawnClass = PlayerPawnClassFinder.Class;

	// use our custom HUD class
	HUDClass = AFPSHUD::StaticClass();
}

void AFPSGameMode::CompleteMission(APawn* InstigatorPawn)
{
	if (InstigatorPawn)
	{
		InstigatorPawn->DisableInput(nullptr);

		if (SpectatingViewpointClass)
		{
		TArray<AActor*> ReturnedActors;
		UGameplayStatics::GetAllActorsOfClass(this, SpectatingViewpointClass, ReturnedActors);

		//Change viewtarget if any valid actor found
		if (ReturnedActors.Num() > 0)
		{
			AActor* NewViewTarget = ReturnedActors[0];

			APlayerController* PC = Cast<APlayerController>(InstigatorPawn->GetController());
			if (PC)
			{
				PC->SetViewTargetWithBlend(NewViewTarget, 0.5f, EViewTargetBlendFunction::VTBlend_Cubic);

			}
		}
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("SpectatingViewpointClass is nullptr. Please update GameMode class with valid subclass. Cannot change spectating view target."))
		}
	}
	OnMissionCompleted(InstigatorPawn);
}
```

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [November 16, 2018, 3:49am UTC](https://forums.unrealengine.com/t/ugameplaystatics-getallactorsofclass-is-inaccessible/437723/2 "2018-11-16T03:49:49Z")

</div>

It hsould work, i dont see it being private… not to mention it pointless making that function private.

But keep in mind that function was made for blueprint use anyway (look Kismet name in path), in C++ generally you should use iterators instead like TActorIterator, which instead of finding all objects and create array that you need to loop thruu anyway, allows to loop thru all object on the go one by one as it finds those and you can process them on the go or do selection, as well as break the loop mid way, making it more efficient and performance freidnly, blueprint does not support iterator so that function was made. Here wiki discribing it, but since wiki is damaged click “View Source”

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...
