C++ Struct Crashing Editor?

I’m a little new to c++ programming in ue4 and I came across an issue with creating a struct.
This is what I have written so far:

struct FItemStruct

	UPROPERTY(VisibleAnywhere, Category = ItemStructure)
		FText Name;

	UPROPERTY(VisibleAnywhere, Category = ItemStructure)
		bool IsStackable;

	UPROPERTY(VisibleAnywhere, Category = ItemStructure)
		int MaxStackSize;

	UPROPERTY(VisibleAnywhere, Category = ItemStructure)
		bool IsConsumable;

	UPROPERTY(VisibleAnywhere, Category = ItemStructure)
		float Durability;

	UPROPERTY(VisibleAnywhere, Category = ItemStructure)
		FText Description;

	UPROPERTY(VisibleAnywhere, Category = ItemStructure)
		UClass* ItemBP;

When I have the struct in, it crashes. When I comment the whole thing out, it’s just fine. So maybe I’m implementing it wrong? I have functionality for what I want to do working in blueprint, I’m just trying to move it to code (mostly as practice). What I’m trying to recreate is this:

Any help would be greatly appreciated!

Can you provicde logs? from Saved/Logs in your project directory, crashes usually leave info there what happened.

From breath look, you could try to change GENERATED_USTRUCT_BODY() which is outdated macro to GENERATED_BODY()

Also some tip, create C++ class for your item blueprints, even if it will be empty, it will at least let you use TSubclassOf which will limit selection to item blueprint. You can also add Abstract specifier to it’s UCLASS so C++ item class won’t apper in selection either. I would also declere item properties in C++, it will make items ferther usable in C++

Structs are… iffy. I’ve had entire projects completely ruined and broken beyond repair because of structs. Specifically: Adding a variable to a created struct in use. The projects were so corrupted entire segments that had no relationship with the struct would cause crashing.

I’d try to remake the struct from scratch. That saved my last project. Granted I had to restore an older backup since the struct had completely broken the current version but remaking it solved everything for me. Not sure why it happens.

Thats why you should avoid doing hot reload in such cases, avoid changing varable structure and order that is already used in assets (it even better to leave unsued variable behind)

The problem was I named the c++ struct the same as one I tested in the engine in BP. So it crashed because they both had the same name! I do have the class for the BP written below the struct! Many people have told me to use TSubclassOf, so I switched it! Still fairly new so advice is always welcome!

Some people have told me to keep the editor when closed while doing this. So I’ll make sure to do that! I imagine I’ll need to change some things later so I hope it doesnt mess anything up. If so, I keep backup code regularly!

If feasible yes, but sometimes you have to. For me it was evolving my inventory system to augment my equipment system. No way around it. Deleting the struct and remaking it, going through every widget, every slot, every blueprint and make them functional again solved it. Now the struct works. I can add more variables if I want, no problem. The original one was just broken. For some reason.

That’s great! Glad you got it fixed :slight_smile:

I figured out why it crashed! I had previous did everything in BP to make sure it worked and as I was transferring it all to code, I named the struct in C++ the same as I did in engine, so it crashed because they both had the same name!