Error after live coding


LoginId:c94d24654bb053080c17c2ad5040f05a
EpicAccountId:fccedefcd3d646a6a9f2c9f009701903

Fatal error: [File:D:\build++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\Templates\Casts.cpp] [Line: 10] Cast of World /Game/UEDPIE_0_Sandbox.Sandbox to Gun failed

UnrealEditor_CoreUObject
UnrealEditor_SimpleShooter_patch_0!AShooterCharacter::BeginPlay() [D:\unreal\Unreal Projects\SimpleShooter\Source\SimpleShooter\ShooterCharacter.cpp:22]
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll

Even if I built it, it didn’t update the game, so I ran the game after live coding.
But the picture-like screen keeps popping up, shutting down Unreal.


	UPROPERTY(EditDefaultsOnly)
	TSubclassOf<AGun> GunClass;

	UPROPERTY()
	AGun* Gun;
void AShooterCharacter::BeginPlay()
{
	Super::BeginPlay();
	UE_LOG(LogTemp, Error, TEXT("MoveRight AxisValue:"));

	
	Gun = GetWorld()->SpawnActor<AGun>(GunClass);


	GetMesh()->HideBoneByName(TEXT("weapon_r"), EPhysBodyOp::PBO_None);
	
	Gun->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("WeaponSocket"));


	Gun->SetOwner(this);
}

Check at the line 10 of your Cast.cpp, theres something that makes it crash there. Otherwise: close the editor(ue), ctrl + shift + b, development build, then reopen UE.

image

I searched cast.cpp in vscode but there are too many. Am I doing something wrong?

I’ve already tried this method. I tried this method, but there was an error like that.

The cast.cpp isnt in the same folder. it says the whole route of your folder. File:D\Build++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private/Templates\Casts.cpp
search it manually or write castS.cpp (theres an s at the end).

in your screenshot, the search bar says \Engine\Plugins rather than Source\Runtime

But from what I read, if its a cast issue, I’d say it has a hard time casting the world. So the issue is at the first line. Gun = GetWorld()->SpawnActor(…)

Did you initialize the gun in the constructor?
GunClass = AGun::StaticClass();

What did you set GunClass to in Unreal?

image
Is this right?

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

#include "Templates/Casts.h"

DECLARE_LOG_CATEGORY_EXTERN(LogCasts, Log, All);
DEFINE_LOG_CATEGORY(LogCasts);

void CastLogError(const TCHAR* FromType, const TCHAR* ToType)
{
	**UE_LOG(LogCasts, Fatal, TEXT("Cast of %s to %s failed"), FromType, ToType);**
    for(;;);
}

The contents of the 10th line were locked between **.

I didn’t reset it

Strangely, even if I build it, it’s not updated when it goes into Unreal.
Every time I go into Unreal, I have to do live coding.

image

After reading the error, I think this is the problem.
Gun = GetWorld()->SpawnActor(GunClass);

It’s no use. The error is the same.

I did “Gun Class” from “Unreal” to “None”
Gun->SetOwner(this);
There’s an error here

Gun->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("WeaponSocket"));

Gun->SetOwner(this);

I think there’s a problem with the code itself

The writing is getting too long. I’m sorry.

void AShooterCharacter::BeginPlay()
{
	Super::BeginPlay();
	UE_LOG(LogTemp, Error, TEXT("MoveRight AxisValue:"));

	Gun = GetWorld()->SpawnActor<AGun>(GunClass);

	GetMesh()->HideBoneByName(TEXT("weapon_r"), EPhysBodyOp::PBO_None);
	
	// Gun->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("WeaponSocket"));

	// Gun->SetOwner(this);
}

Once I’ve annotated the last two lines, there’s no error. But the gun isn’t in the character’s hands. It’s somewhere in the world. It’s because no subrelationships are set in the lectures.
But when I tried it again, I got an error again.


From the code above

Gun->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("WeaponSocket"));

If you delete the annotation of this code, there is no error.

image

It’s a good sub-list.
But when I tried it again, I got an error again.
I did it the same way. Sometimes I can and sometimes I can’t.


The way I tried it, I deleted the annotation line by line, like the method I did at the top, so I didn’t get any errors when I played it. However

Gun = GetWorld()->SpawnActor<AGun>(GunClass);

GetMesh()->HideBoneByName(TEXT("weapon_r"), EPhysBodyOp::PBO_None);

These two lines of code also don’t get an error if you annotate the first line code and then play it after live coding.
After that, if I delete the annotation of the first line and play it after live coding, there is no error.
as such

Gun->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("WeaponSocket"));

I’ve even tried this code. There’s no error up to this point. But I’m not sure if SetOwner works.

The important thing is that if you live-coded and play the codes all at once, there will be another error. Is my laptop the problem…

The comments are too long. Thank you for reading them :cold_sweat:

Oh my god I’ve solved it. I’ve searched Google a lot.

The solution is as follows.

We need to go into the error-prone project folder
image
It’s a folder with this.

And deleted the Binaries and Intermediate and DerivedDataCache folders.
Once you’ve deleted it, double-click the project again to run it. Then you’ll see a window.
This is the window that comes out because I deleted that folder.
Whatever comes up, press ok and wait for the project to reopen. Just wait and it will open.

Then it can be updated via build. I’ve seen a post saying that if the code gets twisted, I erase that folder. I don’t know if it’s true…

You need to build with Unreal closed before you re-open it, remember? Also be sure you’re using the right task.

You likely needed to rebuild again. The error you got didn’t match your code.

The template version of SpawnActor i.e. SpawnActor performs a cast i.e. it’s basically

AActor* SpawnActotr(...); // #1
template<class T>
T* SpawnActor(...)
{
    return Cast<T>(SpawnActor(...)); // call #1 then cast to T.
}

And it was trying to cast World to Gun which failed.

I didn’t remember that… but I did build like a habit before Unreal run. But it didn’t work out weirdly just this time…

How do I check it?

Are you saying there was an error because you failed to cast?

By reading its the right task. It should be ProjectNameEditor Win64 Development Build.

I’m saying what was spawned wasn’t an AGun

I did what you said before I went into Unreal. But sometimes it doesn’t get updated. Why is that? It still does…

I understand now.

Privacy & Terms