x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:

 USTRUCT(BlueprintType)
 struct FItemStruct
 {
     GENERATED_USTRUCT_BODY()
 
     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: alt text

Any help would be greatly appreciated!

Product Version: UE 4.21
Tags:
structcapture.png (261.1 kB)
more ▼

asked Mar 14 '19 at 05:52 PM in C++ Programming

avatar image

KOALASHNIZZLE
1 1

avatar image Shadowriver Mar 14 '19 at 05:56 PM

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++

avatar image KOALASHNIZZLE Mar 14 '19 at 09:52 PM

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!

avatar image Crowley Caine Mar 14 '19 at 06:27 PM

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.

avatar image Shadowriver Mar 14 '19 at 09:41 PM

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)

avatar image Crowley Caine Mar 14 '19 at 09:45 PM

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.

avatar image KOALASHNIZZLE Mar 14 '19 at 09:56 PM

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!

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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!

more ▼

answered Mar 14 '19 at 09:49 PM

avatar image

KOALASHNIZZLE
1 1

avatar image Crowley Caine Mar 14 '19 at 09:51 PM

That's great! Glad you got it fixed :-)

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question