Using UMG with C++

I’ve followed this tutorial in an attempt to use a UMG widget I’ve defined in the editor. While the build succeeds, when I check the error list in visual studio, there are literally a hundred errors–most of which are failure to open sources files included in UMG.h. I’ve checked several times and looked at different tutorials/questions on this subject and have added the right things in Build.cs, added the umg/slate includes in ProjectName.h, built, rebuilt, etc. but I’m still getting those errors.

Has anyone else had this issue? What could be wrong?

Add module UMG in YouProjecName.Build.cs.

Add UMG.h includes in ProjecName.h

I don’t got your problems.

Can you post your codes?
Let me have a look.

ProjectName.h

#ifndef __PROJECT_H__
#define __PROJECT_H__

#include "EngineMinimal.h"

#include "Runtime/UMG/Public/UMG.h"
#include "Runtime/UMG/Public/UMGStyle.h"
#include "Runtime/UMG/Public/Slate/SObjectWidget.h"
#include "Runtime/UMG/Public/IUMGModule.h"
#include "Runtime/UMG/Public/Blueprint/UserWidget.h"

#endif

ProjectName.Build.cs

using UnrealBuildTool;

public class Project: ModuleRules
{
	public Project(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG" });
		PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
	}
}

After compiling, I get this:

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

And yet, at the same time, this:

Don’t bother about intellisense errors, UnrealHeaderTool and UnrealBuildTool generate lot of defines and code and Intellisense goes nut with it.

Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped means that everything compiled and you should works fine :slight_smile:

Agree with you.
Intellisense errors can be ignored.

Thanks! But as I trained myself to ignore the existence of these errors this morning, I tried to declare a UUserWidget after including "Blueprint/UserWidget.h" at the top of my file–and this time, the build failed. UUserWidget is not sensed as a type name, and a ‘cannot open source’ error occurs.

If you’re interested in integrating UMG with Slate, you can read our guide here.