Certain source folder name get broken in #include of UHT generated file

This happened during the 5.6 update process.

It looks similar to the issue reported at the link below :

[Content removed]

but the exact symptoms are different, and the hotfix mentioned in that post did not resolve our problem.

In our project source folder, there is a folder called “CoreUi”.

For example, we have a header file like this:

OurProject/Source/SomeModuleA/Runtime/Ui/Public/CoreUi/SomeFileA.h

Then, in other cpp files, it is included like this:

include “CoreUi/SomeFileA.h”

However, in the .gen.cpp file generated by UHT, we found that it becomes:

include “i/SomeFileA.h”

In other words, the front “CoreU” part of the folder name is missing.

When we renamed the folder to something else (for example, XoreUi), the problem disappeared.

We could simply rename it, but that would require a proper explanation to the team.

We were not able to reproduce this issue in the QAGame project that comes with UE5.6.

So it seems likely that something specific to our project settings or codebase is involved.

However, since this started happening during the upgrade to 5.6,

we would like to know if there is any change in 5.6 that could potentially cause this kind of behavior.

Thanks!

DJ

[Attachment Removed]

I think this is happening because you have an include path in this module which has a longer prefix than the entry that should be matching, and the code is just checking for prefix match, rather than checking for whole path segments. That would explain why renaming the module to a different name fixes the problem, and why it’s not trivially reproducable with QAGame, but I can’t be sure without more information.

Could you please try changing the `GetShortestIncludePath` method in `Engine\Source\Programs\Shared\EpicGames.UHT\Utils\UhtSession.cs` to the following and see if it solves your problem?

public string GetShortestIncludePath(UHTManifest.Module moduleObj, string filePath)
		{
			string? relativePath = null;
			FileReference fileRef = new FileReference(filePath);
			foreach (string includePath in moduleObj.IncludePaths)
			{
				DirectoryReference includePathRef = new DirectoryReference(includePath);
				if (fileRef.IsUnderDirectory(new(includePath)))
				{
					if (relativePath == null || (filePath.Length - includePath.Length - 1) < relativePath.Length)
					{
						relativePath = fileRef.MakeRelativeTo(includePathRef);
					}
				}
			}
 
			// This will create a "../" path which is not great
			if (relativePath == null)
			{
				string? includePath = moduleObj.IncludePaths.Find(includePath => includePath.StartsWith(moduleObj.BaseDirectory, StringComparison.Ordinal));
				if (includePath == null)
				{
					Session.Logger.LogWarning("There are no include paths in module {ModuleName} for {FileName}. It will be included by a \"../\" path external to the module.", moduleObj.Name, filePath);
					includePath = moduleObj.IncludePaths.FirstOrDefault(".");
				}
				relativePath = Path.GetRelativePath(includePath!, filePath);
			}
			return relativePath!.Replace("\\", "/", StringComparison.Ordinal);
		}

If this doesn’t work for you, would you be able to attach your module’s `.Build.cs` file?

[Attachment Removed]

Thanks very much for confirming.

We’re looking at submitting this change for inclusion in future Unreal Engine releases, as the current behaviour is not intended, so I would suggest you apply this change to your source Unreal Engine.

[Attachment Removed]

The change you gave works indeed!

We have “Core” folder right above the “CoreUi” folder, and that is probably the reason to clamp the CoreU (includePath.Length + 1),

So do you consider submit the change to UhtSession.cs? or is it a test code to figure out the reason?

We can either pre-apply the change, or stick to the new UHT rule if it is intended.

[Attachment Removed]