Editor crash after adding struct in C++


I have added struct to project using add code to project. Everything compiles, but once I load editor it crashes.
From the debug it looks like this call from generated file crashes.

ReturnPackage = CastChecked<UPackage>(StaticFindObjectFast(UPackage::StaticClass(), NULL, FName(TEXT("/Script/Uprising")), false, false));

Error: Cast of NULL to Package failed

What can be cause?


Could you post the code from the struct you just added?

Sure thing, it was just to test actualy so nothing special

I see that you are using the standard c++ ctor. An USTRUCT is a bit different and the constructor must go within a #if CPP block. Try this one (no .cpp file in my case, all in the header):

// UnitStuct.h

#pragma once

#include "UnitStuct.generated.h"

 * Unit struct with default construictor to initialize values
struct Funit_struct

	int8 intUnitStrenght;

#if CPP
	Funit_struct() :
		// Default constructor


Hello Moss,

Thanks for the reply, adding if cpp made it failed as well. But I noticed you didnt used USTRUCT() before declaring struct, which I had. So I removed it and it didnt crash.
I wanted to make it visible in bluprints that why I used USTRUCT(BlueprintType).

Another funny thing. Removing USTRUCT made it work. But if I rebuild solution it says no generated h file found.
I need to add back USTRUCT, rebuild, remove USTRUCT() and then it works after build (not rebuild). Preatty much weird behavior.

D-oh! That was a mistak on mt part :smiley: the USTRUCT() must be there.

Is that 'Uprising script yours? Are you using the struct in it?

Uprising is project name and script is generated with option generate project files. I didnt modify it.

I managed to find solution, apears you need to have dummy class created (derived for example from actor). You cant have just struct added to project.

Strange, might be a bug then.