UFunction C++ 'identifier undefined' error

I am trying to create a UFunction (totally new to this) - following the code in this thread here.

I created a c++ blueprint function class and copied the code into the .h and .cpp files relatively however I get -

a ‘UGeometryCollection’ is undefined error in VS as shown

not sure what I am doing wrong here? I assume I need to declare these somewhere but not sure how and what to do?

Hello @Fnordcorps ,
The problem isn’t within the UFUNCTION but in the UGeometryCollection itself. It said that undefined error in VS because you need to declare it first like what you are asuming.

What you can do to fix this kind of problem is:

  1. forward declare your undeclared class in the header file like below:
#pragma once

#include "CoreMinimal.h"
#include "X.h"
#include "X.generated.h"

**class UGeometryCollection;**

/**
 * 
 */
UCLASS()
class Y_API AX : public AActor

By forward declaring class UGeometryCollection in header file, the problem in header file will be fixed, but to use it on .cpp, you need to include it in the .cpp itself (Will do it in step 2)

  1. Include the header file of UGeometryCollection in .cpp file
#include "GeometryCollection/GeometryCollectionObject.h"

If you want to know how to look for the header file, you can just google Unreal Engine + your class name (Exm: Unreal Engine UGeometryCollection) and look for this kind of page
UGeometryCollection | Unreal Engine Documentation
You will find the include path there

  1. Compile it first. If it’s success then done. BUT some class need more action to do like this UGeometryCollection (btw cpp UMG and AI related also need more action). This error is happening because the module is not included yet in YourProjectName.Build.Cs

  2. Include the module in YourProjectName.Build.Cs.


using UnrealBuildTool;

public class X : ModuleRules
{
	public X(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject",  . . .,  "GeometryCollectionEngine" });
	}
}

Add GeometryCollectionEngine inside PublicDependencyModuleNames. You can also know the module name by the same method as looking for the include path.
image

Last Step just compile it!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.