Hiho, I have a problem.
I can export and start the game.
but you can’t play it.
There is an error message that is always related to the movingplatform.cpp.
If I delete all the objects that were created from a movingplatform.cpp, then I can play, but it’s just empty…
I have no idea what that could be
MovingPlatform.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MovingPlatform.generated.h"
UCLASS()
class OBSTACLEASSAULT_API AMovingPlatform : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMovingPlatform();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
private:
UPROPERTY(EditAnywhere, Category="Moving")
FVector PlatformVelocity = FVector(100, 0, 0);
FVector StartLocation;
UPROPERTY(EditAnywhere, Category="Moving")
float MovedDistance = 100;
UPROPERTY(EditAnywhere, Category="Rotation")
FRotator RotationVelocity = FRotator(0, 0, 0);
UPROPERTY(EditAnywhere, Category="Setting")
bool IsMoving = false;
UPROPERTY(EditAnywhere, Category="Setting")
bool IsRotate = false;
void MovePlatform(float DeltaTime);
void RotatePlatform(float DeltaTime);
bool ShouldPlatformReturn() const;
float GetDistanceMoved() const;
};
MovingPlatform.cpp from Unreal Engine C++ Course
// Fill out your copyright notice in the Description page of Project Settings.
#include "MovingPlatform.h"
// Sets default values
AMovingPlatform::AMovingPlatform()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMovingPlatform::BeginPlay()
{
Super::BeginPlay();
StartLocation = GetActorLocation();
FString Name = GetName();
UE_LOG(LogTemp, Display, TEXT("BeginPlay: %s"), *Name);
}
// Called every frame
void AMovingPlatform::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (IsMoving)
{
MovePlatform(DeltaTime);
}
if (IsRotate)
{
RotatePlatform(DeltaTime);
}
}
void AMovingPlatform::MovePlatform(float DeltaTime)
{
if (ShouldPlatformReturn())
{
FVector MoveDirection = PlatformVelocity.GetSafeNormal();
StartLocation = StartLocation + MovedDistance*MoveDirection;
SetActorLocation(StartLocation);
PlatformVelocity = -PlatformVelocity;
}
else
{
FVector CurrentLocation=GetActorLocation();
CurrentLocation=CurrentLocation + DeltaTime*PlatformVelocity;
SetActorLocation(CurrentLocation);
}
}
void AMovingPlatform::RotatePlatform(float DeltaTime)
{
AddActorLocalRotation(RotationVelocity * DeltaTime);
}
bool AMovingPlatform::ShouldPlatformReturn() const
{
return GetDistanceMoved() > MovedDistance;
}
float AMovingPlatform::GetDistanceMoved() const
{
return FVector::Dist(StartLocation, GetActorLocation());
}
Error by Game Start
Fatal error: [File:D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\Serialization\AsyncLoading2.cpp] [Line: 1812]
ObjectSerializationError: /Game/main (0x7F8912BACDC75769) /Game/main (0x7F8912BACDC75769) - BP_PushingCube_C /Game/main.Main:PersistentLevel.BP_PushingCube_C_8: Bad export index 905969663/322.
0x00007ff6a03931a5 ObstacleAssault.exe!FExportArchive::HandleBadExportIndex() []
0x00007ff6a0379f3f ObstacleAssault.exe!FExportArchive::operator<<() []
0x00007ff6a0360a9c ObstacleAssault.exe!FArchiveUObject::SerializeWeakObjectPtr() []
0x00007ff6a063bbc5 ObstacleAssault.exe!TArrayPrivateFriend::Serialize<TScriptDelegate<FNotThreadSafeNotCheckedDelegateMode>,TSizedDefaultAllocator<32> >() []
0x00007ff6a06a09b7 ObstacleAssault.exe!FMulticastSparseDelegateProperty::SerializeItemInternal() []
0x00007ff6a069e30d ObstacleAssault.exe!FMulticastSparseDelegateProperty::SerializeItem() []
0x00007ff6a0404dfa ObstacleAssault.exe!SerializeUnversionedProperties() []
0x00007ff6a0403f1d ObstacleAssault.exe!UStruct::SerializeTaggedProperties() []
0x00007ff6a05c4c37 ObstacleAssault.exe!UObject::SerializeScriptProperties() []
0x00007ff6a05c3f6a ObstacleAssault.exe!UObject::Serialize() []
0x00007ff6a05c3c80 ObstacleAssault.exe!UObject::Serialize() []
0x00007ff6a5452777 ObstacleAssault.exe!AActor::Serialize() []
0x00007ff6a038870a ObstacleAssault.exe!FAsyncPackage2::EventDrivenSerializeExport() []
0x00007ff6a038b3b0 ObstacleAssault.exe!FAsyncPackage2::Event_ProcessExportBundle() []
0x00007ff6a038c153 ObstacleAssault.exe!FEventLoadNode2::Execute() []
0x00007ff6a038c70d ObstacleAssault.exe!FAsyncLoadEventQueue2::ExecuteSyncLoadEvents() []
0x00007ff6a03a62cc ObstacleAssault.exe!FAsyncLoadingThread2::Run() []
0x00007ff69fff4d68 ObstacleAssault.exe!FRunnableThreadWin::Run() []
0x00007ff69ffe88b7 ObstacleAssault.exe!FRunnableThreadWin::GuardedRun() []
0x00007ffdfd3f7374 KERNEL32.DLL!UnknownFunction []
Crash in runnable thread FAsyncLoadingThread