Getting Player Viewpoint

Hi Team,
I was trying to do the Getting viewport challenge on my own.
But I wrote an invalid code.
And after compiling it UE crashed.
And when I try to open it again.

I am always getting the crash warning and project is not starting up.

Hi,
Right now we aren’t supporting Unreal Engine 5 - we are waiting until closer to the release date.

However, the best way to resolve this version in any version of unreal is to Open your code editor then undo your changes and rebuild. Then you should be able to launch the editor again.

I hope this helps.

Hi @beegeedee ,
It’s worth a try.
But how will I rebuild from vs code without using UE editor?
I have reverted the changes back.

Your issue could have been related to your code. In the future please show the top of the crash report. It has the more useful information.

To compile from VS Code

Ctrl + Shift + B > ProjectNameEditor Platform Development Build.

Where ProjectName is the name of your project and Platform is the platform you’re targeting e.g. Win64

Hi,

I am attaching my crash report here:

LoginId:c004c5664a5dc0fbae08aeacd7d6991c
EpicAccountId:afe2b3bc194243689822ee34a605dcc3

Fatal error: [File:D:/build/++UE5/Sync/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectGlobals.cpp] [Line: 2603] UObject() constructor called but it's not the object that's currently being constructed with NewObject. Maybe you are trying to construct it on the stack, which is not supported.

UnrealEditor_CoreUObject
UnrealEditor_Engine

An this is my Grabber.h:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "GameFramework/PlayerController.h"
#include "Engine/World.h"
#include "Grabber.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UGrabber : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UGrabber();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};

And this is my source file:

// Fill out your copyright notice in the Description page of Project Settings.


#include "Grabber.h"

// Sets default values for this component's properties
UGrabber::UGrabber()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}

// Called when the game starts
void UGrabber::BeginPlay()
{
	Super::BeginPlay();

	UE_LOG(LogTemp, Warning, TEXT("Grabber reporting for duty!"));
}

// Called every frame
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	FVector Location;
	FRotator Rotation;

	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(Location, Rotation);

	UE_LOG(LogTemp, Warning, TEXT("PlayerLocation is: %s"), *Location.ToString());
	UE_LOG(LogTemp, Warning, TEXT("PlayerRotation is: %s"), *Rotation.ToString());
}

I performed a build.
But it didn’t help.

Thank You.

Was compilation successful? What was the output of building?

The first time it did build.
But now it’s giving the following:

> Executing task in folder BuildingEscape: Engine\Build\BatchFiles\Build.bat BuildingEscape Win64 Development D:\BuildingEscape\BuildingEscape.uproject -waitmutex <

'"C:\Program Files\Epic Games\UE_5.0EA\Engine\Build\BatchFiles\GetDotnetPath.bat"' is not recognized as an internal or external command,
operable program or batch file.
Win64 using Manual SDK 10.0.19041.0
Target is up to date
Total execution time: 0.98 seconds

I am sorry I restarted my vs code so lost my first build output.

Well that says it’s up to date so I’m assuming it compiled successfully.

Could you provide your other files please?

Hi @DanM ,

I am attaching my other files below:

BallComponent.h:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "BallComponent.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UBallComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UBallComponent();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

		
};

BallComponent.cpp:

// Fill out your copyright notice in the Description page of Project Settings.


#include "BallComponent.h"
#include "GameFramework/Actor.h"

// Sets default values for this component's properties
UBallComponent::UBallComponent()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


// Called when the game starts
void UBallComponent::BeginPlay()
{
	Super::BeginPlay();

	// UE_LOG(LogTemp, Error, TEXT("This is an error!"));
	// UE_LOG(LogTemp, Warning, TEXT("This is a warning!"));
	// UE_LOG(LogTemp, Display, TEXT("This is just a display message!"));

	FString ActorName = GetOwner()->GetName();

	UE_LOG(LogTemp, Warning, TEXT("%s"), *ActorName);

	auto ActorLoc = (GetOwner()->GetActorLocation()).ToString();

	UE_LOG(LogTemp, Warning, TEXT("%s"), *ActorLoc);
	
}


// Called every frame
void UBallComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// ...
}

BuildingEscape.h:

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"

BuildingEscape.cpp:

// Copyright Epic Games, Inc. All Rights Reserved.

#include "BuildingEscape.h"
#include "Modules/ModuleManager.h"

IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, BuildingEscape, "BuildingEscape" );

BuildingEscapeGameModeBase.h:

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "BuildingEscapeGameModeBase.generated.h"

/**
 * 
 */
UCLASS()
class BUILDINGESCAPE_API ABuildingEscapeGameModeBase : public AGameModeBase
{
	GENERATED_BODY()
	
};

BuildingEscapeGameModeBase.cpp:

// Copyright Epic Games, Inc. All Rights Reserved.


#include "BuildingEscapeGameModeBase.h"

OpenDoor.h:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "GameFrameWork/Actor.h"
#include "Engine/TriggerVolume.h"
#include "GameFramework/PlayerController.h"
#include "Engine/World.h"
#include "OpenDoor.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UOpenDoor : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UOpenDoor();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

private:

	UPROPERTY(EditAnywhere)
	ATriggerVolume* PressurePlate;

	UPROPERTY(EditAnywhere)
	float OpenSpeed = 1.0f;

	UPROPERTY(EditAnywhere)
	float CloseSpeed = 1.0f;

	UPROPERTY(EditAnywhere)
	float CloseDelay = 2.0f;

	float InitialYaw, CurrentYaw, TargetYaw; 
	float LastOpenTime = 0.0f;

	
	AActor* ActorThatOpens;
	bool IsDoorOpen, IsDoorClose;

	void OpenDoor(float DeltaTime);
	void CloseDoor(float DeltaTime);		
};

OpenDoor.cpp:

// Fill out your copyright notice in the Description page of Project Settings.


#include "OpenDoor.h"

// Sets default values for this component's properties
UOpenDoor::UOpenDoor()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


// Called when the game starts
void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();

	InitialYaw = GetOwner()->GetActorRotation().Yaw;
	CurrentYaw = InitialYaw;
	TargetYaw = InitialYaw + 90.0f;

	IsDoorOpen = false;
	IsDoorClose = true;

	if (PressurePlate == NULL)
	{
		UE_LOG(LogTemp, Error, TEXT("The actor '%s' have OpenDoor Component set to NULL"), *(GetOwner()->GetName()));
	}

	ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
}

void UOpenDoor::OpenDoor(float DeltaTime)
{
	auto TickRotation = GetOwner()->GetActorRotation();

	CurrentYaw = FMath::Lerp(CurrentYaw, TargetYaw, DeltaTime*OpenSpeed);

	TickRotation.Yaw = CurrentYaw;

	GetOwner()->SetActorRotation(TickRotation);
}

void UOpenDoor::CloseDoor(float DeltaTime)
{
	auto TickRotation = GetOwner()->GetActorRotation();

	CurrentYaw = FMath::Lerp(CurrentYaw, InitialYaw, DeltaTime*CloseSpeed);

	TickRotation.Yaw = CurrentYaw;

	GetOwner()->SetActorRotation(TickRotation);
}

// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (PressurePlate != NULL)
	{
		if (PressurePlate->IsOverlappingActor(ActorThatOpens))
		{
			OpenDoor(DeltaTime);
			LastOpenTime = GetWorld()->GetTimeSeconds();
		}
		else
		{
			auto CloseTime = GetWorld()->GetTimeSeconds();

			if (CloseTime > LastOpenTime + CloseDelay)
			{
				CloseDoor(DeltaTime);
			}
		}
	}

	// UE_LOG(LogTemp, Warning, TEXT("%s"), *CurrentRotation.ToString());
	// UE_LOG(LogTemp, Warning, TEXT("The Yaw is: %f"), CurrentRotation.Yaw);
}

Not really seeing an issue there. Could you try closing Unreal and then deleting the Binaries and Intermediate folders of your project and then re-opening the project?

Thank You,
It worked.
But I didn’t understand the solution.
How did deleting Binaries fix it?

It happens sometimes that the binaries get out of sync/are corrupted. Not very often and usually a build works. But the fix of deleting the binaries folder is simple enough and fixes a number of things. The only time I’ve ever seen this happen is when I build the code outside of Unreal (i.e. not using compile from within the editor) but it doesn’t happen often.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms