C++おいて、ヘッダーファイルに generated.h をincludeできない

こちらのページの内容を学習しているのですが、ヘッダーファイルにgenerated.hをincludeすることができません。
調べてみても同じ事例を見つけられず、どなたか原因と解決策をご存知ないでしょうか。

使用しているバージョンは5.2.1になります。

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "CPPCalcType.generated.h" //ここでError

/**
 * 
 */
class CPP_BP_API CPPCalcType
{
public:
	CPPCalcType();
	~CPPCalcType();
};

▽エラー
cannot open source file “CPPCalcType.generated.h”

Hi,

May you be great.

.generated.h files are generated by unreal’s reflection system, so you have to do anything about that.

If I understand correctly, you want to create a container in order to add your enums, so there are a few steps to follow.

  1. you don’t need a .cpp file, only .h;
  2. you don’t need any include, dele all;
  3. create your enum classes.

Here is a example:

MyTypes.h

#pragma once

UENUM()
enum class EMyConfirmType : uint8
{
	Yes,
	No
};

UENUM(BlueprintType)
enum class EMyMovementState : uint8
{
	Idle,
	Walk,
	Run,
	Sprint
};

// ....

In order to use your enums, simple include it in your target .h file, e.g.:

#pragma once

#include "CoreMinimal.h"
#include "Characters/SVBaseCharacter.h"
#include "MyTypes.h"
#include "SVEnemyCharacter.generated.h"

UCLASS()
class GAME_API AEnemyCharacter : public ABaseCharacter
{
	GENERATED_BODY()
	
public:
	EMyMovementState MovState = EMyMovementState::Idle;

};

bye.

1 Like
#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "CPPCalcType.generated.h"

/**
 * 
 */
UCLASS()
class CPP_BP_API UCPPCalcType : public UObject
{
	GENERATED_BODY()
	
};

.generated requires the UCLASS macro.

The lowest implementation of a class you can go is UOBject unless you are making a struct or enum.

For blueprint visibility you would need

UCLASS(Blueprintable, BlueprintType)

Blueprintable = can make blueprint variant.
BlueprintType = can show up as variable type.

1 Like

Thanks for the explanation.
To begin with, the description in the reference material and the one you gave me are so different that I will try again with the code you gave me.

However, this time another error is occurring, and I think I need to solve this one first.
(Influenced by changing the version to 5.4?)

This error is completely different from the title of your question, so I will look into it a little more and post another question.

Sorry for the half-■■■■■ way, but I will get back to you if there is any progress!

Thanks for letting us know about you too.
As I mentioned in my reply above, I have been plagued with another error, so I will be late learning about the description you gave me.

I apologize, but I will go ahead and find a solution to this error first.

You are probably adding direct folders for the imports instead of adding the correct modules in the build path.

Please post the header file contents.

Your starting and ending brackets don’t seem to match up looking at the error statement.

Hey,

I didn’t think it was so different, because I looked at the link you’ve shared in your post about enumerations. So I thought clarify that would be very helpful.

Your error seems to be brackets issues, you opened but not closed. Can you share your code?

Thank you…!
The header file contents are as follows
The cpp file has already been removed as you said it was not needed.
(The parent actor is created with None)

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"

/**
 * 
 */
class CPP_BP_API ECPPCalcType
{
public:
	ECPPCalcType();
	~ECPPCalcType();
};

Thank you…!
Yes, at first it was only a problem about enum, but it was also my first time to build a c++ environment, so a lot of things didn’t work…

I’m sorry for the digression from my original question.
The contents of the header file are described above.

You don’t need a main class for an enum container.

Delete the class ECPPCalcType and create your enum class ECPPCalcType, e.g:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

UENUM(BlueprintType)
enum class ECPPCalcType : uint8
{
	Add,
	Subtract,
	Multiply,
	Divide
};

That’s going to work.

And do not forget:

1 Like