Blueprint with C++ class crashes at Component Tab (4.6/4.7)

I am working on a project that requires a derived C++ PlayerController class. I am able to build the class with no issues in both 4.6.1 and 4.7, but if I open the blueprint in components, UE4 crashes.

Here is the crash report:

MachineId:8289D0244DA28BC3686345B5BB799783
EpicAccountId:e869b5b3811c40fe9dc95812ce488747

Access violation - code c0000005 (first/second chance not available)

UE4Editor_UMG + 883686 bytes
UE4Editor_UMG + 1540559 bytes
UE4Editor_CoreUObject + 563956 bytes
UE4Editor_CoreUObject + 1348671 bytes
UE4Editor_CoreUObject + 1471421 bytes
UE4Editor_CoreUObject + 1615878 bytes
UE4Editor_CoreUObject + 1477214 bytes
UE4Editor_CoreUObject + 1350042 bytes
UE4Editor_CoreUObject + 1621364 bytes
UE4Editor_CoreUObject + 1477214 bytes
UE4Editor_CoreUObject + 563956 bytes
UE4Editor_CoreUObject + 1475014 bytes
UE4Editor_Engine + 1640529 bytes
UE4Editor_Engine + 16637402 bytes
UE4Editor_Engine + 1738650 bytes
UE4Editor_Engine + 6522319 bytes
UE4Editor_Engine + 1447759 bytes
UE4Editor_Engine + 8851078 bytes
UE4Editor_Engine + 8881168 bytes
UE4Editor_Core + 713859 bytes
UE4Editor_Core + 714365 bytes
UE4Editor_Core + 842869 bytes
UE4Editor_Engine + 9095109 bytes
UE4Editor_Engine + 9009872 bytes
UE4Editor_Engine + 9020215 bytes
UE4Editor_Engine + 5593062 bytes
UE4Editor_Engine + 5622284 bytes
UE4Editor_Kismet + 3809064 bytes
UE4Editor_UnrealEd + 1804712 bytes
UE4Editor_UnrealEd + 6686342 bytes
UE4Editor!FEngineLoop::Tick() + 3876 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\launchengineloop.cpp:2214]
UE4Editor!GuardedMain() + 479 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\launch.cpp:131]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

I think there is something in my C++ code that the UE4 editor doesn’t like, since the other blueprints that do not use derived classes open fine for both graph and components.

MyNewPlayerController.h

#pragma once

#include "GameFramework/PlayerController.h"
#include "MyNewPlayerController.generated.h"

UCLASS()
class COLLISIONCOURSE_API AMyNewPlayerController : public APlayerController
{
	GENERATED_BODY()
	
public:
	UFUNCTION(BlueprintCallable, Category = "CollisionCourseFuncs")
		static bool Viewport__SetMousePosition(const APlayerController* ThePC, const float& PosX, const float& PosY);
	UFUNCTION(BlueprintCallable, Category = "CollisionCourseFuncs")
		static bool PlayerController_GetControllerID(APlayerController* ThePC, int32& ControllerID);
};

MyNewPlayerController.cpp

#include "CollisionCourse.h"
#include "MyNewPlayerController.h"

bool AMyNewPlayerController::Viewport__SetMousePosition(const APlayerController* ThePC, const float& PosX, const float& PosY)
{
	if (!ThePC) return false;
	//~~~~~~~~~~~~~

	//Get Player
	const ULocalPlayer * VictoryPlayer = Cast<ULocalPlayer>(ThePC->Player);
	//PlayerController::Player is UPlayer

	if (!VictoryPlayer) return false;
	//~~~~~~~~~~~~~~~~~~~~

	//get view port ptr
	const UGameViewportClient * VictoryViewportClient =
		Cast < UGameViewportClient >(VictoryPlayer->ViewportClient);

	if (!VictoryViewportClient) return false;
	//~~~~~~~~~~~~~~~~~~~~

	FViewport * VictoryViewport = VictoryViewportClient->Viewport;

	if (!VictoryViewport) return false;
	//~~~~~~~~~~~~~~~~~~~~

	//Set Mouse
	VictoryViewport->SetMouse(int32(PosX), int32(PosY));

	return true;
}

bool AMyNewPlayerController::PlayerController_GetControllerID(APlayerController* ThePC, int32& ControllerID)
{
	if (!ThePC) return false;

	ULocalPlayer * LP = Cast<ULocalPlayer>(ThePC->Player);
	if (!LP) return false;

	ControllerID = LP->GetControllerId();

	return true;
}

The only thing that I see which might be missing would be some flags and the FObjectInitializer constructor. Here is a simple skeleton which works on my end:

UCLASS(Config = Game, BlueprintType, Blueprintable)
class AMyNewPC: public APlayerController
{
	GENERATED_BODY()

public:
	AMyNewPC(const FObjectInitializer& ObjectInitializer);
}

The constructor is just empty:

AMyNewPC::AMyNewPC(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
}

Updated project to 4.7.2, while I can open the PlayerController I get compilation errors. As soon as I resolve the compilation errors, UE4 crashes.

I’ve also attempted to remove all uses of the nodes, move the entire code to a C++ Function Library (see below), duplicating it and copying the entire PlayerController by hand, but UE4 still crashes with the same Access Violation error.

UPlayerControllerFunctionLibrary::UPlayerControllerFunctionLibrary(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{

}

bool UPlayerControllerFunctionLibrary::ViewportSetMousePosition(const APlayerController* ThePC, const float& PosX, const float& PosY)
{
	if (!ThePC) return false;
	//~~~~~~~~~~~~~

	//Get Player
	const ULocalPlayer * VictoryPlayer = Cast<ULocalPlayer>(ThePC->Player);
	//PlayerController::Player is UPlayer

	if (!VictoryPlayer) return false;
	//~~~~~~~~~~~~~~~~~~~~

	//get view port ptr
	const UGameViewportClient * VictoryViewportClient =
		Cast < UGameViewportClient >(VictoryPlayer->ViewportClient);

	if (!VictoryViewportClient) return false;
	//~~~~~~~~~~~~~~~~~~~~

	FViewport * VictoryViewport = VictoryViewportClient->Viewport;

	if (!VictoryViewport) return false;
	//~~~~~~~~~~~~~~~~~~~~

	//Set Mouse
	VictoryViewport->SetMouse(int32(PosX), int32(PosY));

	return true;
}

bool UPlayerControllerFunctionLibrary::PlayerControllerGetControllerID(APlayerController* ThePC, int32& ControllerID)
{
	if (!ThePC) return false;

	ULocalPlayer * LP = Cast<ULocalPlayer>(ThePC->Player);
	if (!LP) return false;

	ControllerID = LP->GetControllerId();

	return true;
}

Did you changed any components that are contained in the actor?

No, the only component is the inherited transform component.

Good news, I’ve managed to get Player Controller to compile and show the Components Tab without crashing. The problem IS NOT in the C++ code. The issue is somewhere in this area of the blueprint:

Deleting the entirety of this somehow stopped UE4 from crashing upon compiling or showing the component tab. What it is supposed to do is move an element in the HUD to follow the mouse position, basically to act as a mouse cursor.

While this does crash in the components tab, this blueprint was able to compile and run with no issues in 4.6, do I have no idea what or why this part causes the access violation area and crash the engine.

Hey Gamepopper-

As the components tab was removed in 4.7, do you get this crash when selecting the Viewport tab in your blueprint? If you create the same setup in a blueprint based on the default PlayerController class does that blueprint crash as well? Additionally, if you’ve narrowed the issue to the shown section of blueprint. I would try removing a couple nodes at a time to find out which node or combination of nodes is the cause.

Cheers

Yes, it still crashed in 4.7 when selecting the Viewport tab. I’m going to try and narrow the issue now, I suspect it might be from calling the canvas in Player Controller.

Wrote this into the PlayerController, compiling it causes the Editor to Crash, so it must be either Set As Canvas Slot or Setting the Anchors of a Canvas Panel Slot that is causing the Access Violation.

33815-capture1.png

The blueprint code above works fine without crashing when running inside the HUD itself.

Adding the Set Anchors node and Slot as Canvas Slot node to the PlayerController blueprint did not cause me to crash on compile. If you disconnect the other three nodes that lead into the Widget pin do you still crash on compile? How are those three nodes being used? The one labeled GameMode seems to be a variable but I’m not sure what the other two are doing.

Game Mode is a variable of an Object Blueprint
Main HUD is a variable inside Game Mode which stores the HUD blueprint.
Image Cursor is an image in the HUD.

To test this I greated a new blueprint for MyPlayerController, MyHUD, and MyGameMode. Inside the PlayerController I have a variable called GameModeRef that is of type MyGameMode. Inside MyGameMode I created a variable called MainHUD that is of type MyHUD. Inside of MyHUD I created a variable called Image of type Image. This allowed me to construct the setup you posted in your screenshot inside MyPlayerController which did not crash when I compiled it. Could you elaborate on how you set up your variables? Also, if you disconnect the nodes from the Slot as Canvas Slot input node do you still crash on compile?

Hi Gamepopper,

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

Ah sorry, I did what you said earlier and despite not having the variables connected to Slot as Canvas slot, the editor still crashed.

However, I no longer use the blueprint nodes above in the PlayerController, doing the same in the MainHUD, where I can get the Image Cursor directly, doesn’t crash the editor.