Why is there no "New C++ Struct" option?

Under Tools, there’s an option “New C++ Class”, which allows the creation of C++ classes and to see what classes derive from what other classes.
Overall, it makes it way easier to create an unreal class, compared to manually writing the class from scratch.

But there’s no “New C++ Struct” option, while structs have the same issues of classes, it’s way harder to handwrite.

Is this a feature that’s coming or do we manually handwrite it each time?

This is for a few reasons.

  1. Structures rarely have their own file and the tools are built around creating new files for the new type. Structures tend to either be located with a class that uses it or in with a collection of other structures & types. They don’t tend to be on their own until much later if/when they get very large.

  2. Structures are much simpler. In general, structures don’t derive from other structures. While you can do that in C++ with structures in a way you can’t with Blueprint Structures it’s not really something that is made easy because its kind of an advanced feature that can really mess you up if you don’t know what you’re doing.

  3. It’s 3-5 lines of code (depending on what you’re counting). I don’t know how much easier you want it to be.

USTRUCT( )
struct FMyStruct
{
   GENERATED_BODY( )
};

That’s the extent of what a tool will save you. You still have to add all the properties on your own. I find the tool even less helpful to make classes because I don’t want to boot the Editor to make files that I need to close the Editor to compile (which you should absolutely be doing if you’re making new files).

You might be able to write a snippet to make this easier in your IDE of choice. Snippets are sort of like custom auto-completes that you can setup.

You forgot the include and the pragma.

// Copyright copywrong whatever

#pragma once

#include "MyStruct.generated.h"

USTRUCT()
struct YOUR_API FMyStruct {
    GENERATED_BODY()
};

7 lines excluding blanks (or 8 if you like your opening brace on a separate line). Maybe you also need #include CoreMinimal.h? I’m not sure about that one.

It’s likely possible to make a template in the New C++ Class wizard to create a struct (after all, some of the existing templates are decidedly not UObjects). I’m not sure how much work it would be or if it’s even worth the effort.

I didn’t. As I stated in point 1, you don’t generally create structures immediately in their own header file. You’re going to put them in an existing header file. Also, I’d consider the lines for that separate from what you need for a new structure because you need to do that for any other header you make including those that are for classes or structures that aren’t involved in reflection (which the tool doesn’t help with at all).

But the contents aren’t that hard to just know. I think I make new classes just as fast, if not faster, just typing things instead of trying to use any sort of wizard. But I’ve been doing C++ dev for a long time.

1 Like

even Rider sucks at creating structs :frowning: i usually put them in a function library since blueprint cant access struct functions so it fits well

There are many cases when you’d want to, though. Some that might be somewhat common are row structs for data tables that contain a lot of columns, or structs that have a lot of functions in them (for C++ use, obviously).

There are some templates for non-reflected types, for example a Slate widget. So the tool can help you with non-reflected classes and structures.

The main reason to use the wizard (for me, at least) is that it also automatically updates the project file for you.