Comments are causing my compile to fail !? help.

I suddenly started getting “unresolved external symbol” errors.
I found the function causing this, but i dont understand why its causing the errors.

This is the function

void UModelData_RSClass::encode_or_decode_Format_2(bool encode, UMod* Mod, UBuffer_RSClass* byteBuffer)
{
	isDefaulted = false;

	if (encode) {
		/*uint8 propertyCodeEncode = 0;
		PropertyMetadata.KeySort([](int32 A, int32 B) { return A < B; });
		for (const TPair<uint8, FPropertyMetadata>& pair : PropertyMetadata)
		{
			propertyCodeEncode = pair.Key;
			if (PropertyMetadata.FindRef(propertyCodeEncode).OverrideModes_Mods.Contains(Mod)) { //if The Mod contains this propertyCode
				byteBuffer->writeByte(propertyCodeEncode);
				switch (propertyCodeEncode)
				{
					case 2:
						byteBuffer->writeLong(parent_id);
						break;
					case 3:
						byteBuffer->writeStringCp1252NullTerminated(name);
						break;
						//End_Object_Base
					case 11:
						byteBuffer->writeVector_16_Array(vertexPositions, 10);
						break;
					case 12:
						byteBuffer->writeInt_Array(faceIndices1);
						break;
					case 13:
						byteBuffer->writeInt_Array(faceIndices2);
						break;
					case 14:
						byteBuffer->writeInt_Array(faceIndices3);
						break;
					case 15:
						byteBuffer->writeByte_Array(face_material_index);
						break;
					case 16:
						byteBuffer->writeLong_Array(material_ids);
						break;
					case 17:
						byteBuffer->writeInt_Array(faceColors);
						break;
					case 18:
						byteBuffer->writeVector_16_Array(vertexNormals, 1000);
						break;
					case 19:
						{
							byteBuffer->writeShort(faceTextureUCoordinates.Num());
							for (int i0 = 0; i0 < faceTextureUCoordinates.Num(); i0++)
							{
								byteBuffer->writeFloat_16(faceTextureUCoordinates[i0].arr[0], 2048);
								byteBuffer->writeFloat_16(faceTextureUCoordinates[i0].arr[1], 2048);
								byteBuffer->writeFloat_16(faceTextureUCoordinates[i0].arr[2], 2048);
							
								byteBuffer->writeFloat_16(faceTextureVCoordinates[i0].arr[0], 2048);
								byteBuffer->writeFloat_16(faceTextureVCoordinates[i0].arr[1], 2048);
								byteBuffer->writeFloat_16(faceTextureVCoordinates[i0].arr[2], 2048);
							}
						}
						break;
					case 20:
						byteBuffer->writeByte_Array(faceTransparencies);
						break;
					case 21:
						byteBuffer->writeByte_Array(faceRoughness);
						break;
					case 22:
						byteBuffer->writeByte_Array(faceMetallic);
						break;
				}
			}
		}*/
	}
	else
	{
		uint8 propertyCode = 0;
		while (byteBuffer->offset < (byteBuffer->array.Num())) {
			propertyCode = byteBuffer->readByte();
			AddPropertyOverride(propertyCode, Mod);
			switch (propertyCode)
			{
				case 2:
					byteBuffer->readLong(parent_id);
					break;
				case 3:
					byteBuffer->readStringCp1252NullTerminated(name);
					break;
				case 4:
					{
						int64 idTemp = id;
						Recycle();
						id = idTemp;
					}
					break;
				case 11:
					byteBuffer->readVector_16_Array(vertexPositions, 10);
					break;
				case 12:
					byteBuffer->readInt_Array(faceIndices1);
					break;
				case 13:
					byteBuffer->readInt_Array(faceIndices2);
					break;
				case 14:
					byteBuffer->readInt_Array(faceIndices3);
					break;
				case 15:
					byteBuffer->readByte_Array(face_material_index);
					break;
				case 16:
					byteBuffer->readLong_Array(material_ids);
					break;
				case 17:
					byteBuffer->readInt_Array(faceColors);
					break;
				case 18:
					byteBuffer->readVector_16_Array(vertexNormals, 1000);
					break;
				case 19:
					{
						faceCount = byteBuffer->readShort();
						F2DArrayElement_Float faceUV_elem; faceUV_elem.arr.Init(0,3);
						faceTextureUCoordinates.Init(faceUV_elem,faceCount);
						faceTextureVCoordinates.Init(faceUV_elem,faceCount);
						for (int i0 = 0; i0 < faceCount; i0++)
						{
							byteBuffer->readFloat_16(faceTextureUCoordinates[i0].arr[0], 2048);
							byteBuffer->readFloat_16(faceTextureUCoordinates[i0].arr[1], 2048);
							byteBuffer->readFloat_16(faceTextureUCoordinates[i0].arr[2], 2048);
							
							byteBuffer->readFloat_16(faceTextureVCoordinates[i0].arr[0], 2048);
							byteBuffer->readFloat_16(faceTextureVCoordinates[i0].arr[1], 2048);
							byteBuffer->readFloat_16(faceTextureVCoordinates[i0].arr[2], 2048);
						}
					}
					break;
				case 20:
					byteBuffer->readByte_Array(faceTransparencies);
					break;
				case 21:
					byteBuffer->readByte_Array(faceRoughness);
					break;
				case 22:
					byteBuffer->readByte_Array(faceMetallic);
					break;
			}
		}
	}
}

If I simply remove the commented text between the /* and */, the errors disappear.
Why could this be?

I am using Rider and UE4.27.

this case is causing some sort of problem.

				case 19:
					{
						byteBuffer->writeShort(faceTextureUCoordinates.Num());
						for (i0 = 0; i0 < faceTextureUCoordinates.Num(); i0++)
						{
							byteBuffer->writeFloat_16(faceTextureUCoordinates[i0].arr[0], 2048);
							byteBuffer->writeFloat_16(faceTextureUCoordinates[i0].arr[1], 2048);
							byteBuffer->writeFloat_16(faceTextureUCoordinates[i0].arr[2], 2048);
						
							byteBuffer->writeFloat_16(faceTextureVCoordinates[i0].arr[0], 2048);
							byteBuffer->writeFloat_16(faceTextureVCoordinates[i0].arr[1], 2048);
							byteBuffer->writeFloat_16(faceTextureVCoordinates[i0].arr[2], 2048);
						}
						break;
					}

this fails to compile.
However if i remove a couple of lines like this, it compiles

				case 19:
					{
						byteBuffer->writeShort(faceTextureUCoordinates.Num());
						for (i0 = 0; i0 < faceTextureUCoordinates.Num(); i0++)
						{
							byteBuffer->writeFloat_16(faceTextureUCoordinates[i0].arr[0], 2048);
							byteBuffer->writeFloat_16(faceTextureUCoordinates[i0].arr[1], 2048);
						
							byteBuffer->writeFloat_16(faceTextureVCoordinates[i0].arr[0], 2048);
							byteBuffer->writeFloat_16(faceTextureVCoordinates[i0].arr[1], 2048);
						}
						break;
					}

I think this is a bug with ue4’s structs.
If I try to reference an array inside a struct, more than twice within a switch case, I get compile errors.

This error always means that you are using a datatype without including its header. Sometimes your project will just compile until at some point Visual Studio will “notice”.

If you google the name of unreal’s struct you will find a page like this as (probably) the first link:

FVector | Unreal Engine Documentation

There you can see the include you need to add to the file your code lives in.

Also most of Unreal’s basic types are included through the CoreMinimal.h header, which is advised to add to every .h file by default.

To avoid this error popping up at any later moment you can check if your includes are correct for your module by modifying the Build.cs file and recompiling it, then most likely you will see a lot more of this same error right now:

public class SomeModule: ModuleRules {
	public SomeModule(ReadOnlyTargetRules Target) : base(Target) {
		// To test if all headers are included properly, disable unity, disable PCH, enforce IWYU.
		PCHUsage = PCHUsageMode.NoSharedPCHs;
		bEnforceIWYU = true;
		bUseUnity = false;


//// Any includes

	}
}

Thankyou for you suggestion :slight_smile:

I have tried including coreMinimal and also the structs file where my custom structs are declared. This didn’t make a difference.

I think the “unresolved external symbol” is a knock-on affect. The class where the problem lies cannot be compiled, so classes relying on it come up with the “unresolved external symbol” error.

See my second comment in this thread, how can you explain that with a missing include?

Also if i simply do the same code but not in a switch statement, it compiles.

This I think is possible, I have seen something similar before.

What I have not seen before, is code not compiling because of the content of a comment. If the error appears as an Intellisense notification (or Rider?) you can safely ignore it, because the errors are usually nonsense. If the code does not compile at all because of the contents of that comment, or does not compile at all (finish building successfully) simply because you access a struct more than twice, that would be a mystery to me.

Triple check the includes, and of vars ones not listed here including types you access through a container:

custom types:
UMod
UBuffer_RSClass
FPropertyMetadata

unknown types:
vertexPositions
vertexNormals
faceColors
material_ids
face_material_index
faceIndices1
faceIndices2
faceIndices3
F2DArrayElement_Float
faceTextureUCoordinates
faceTextureUCoordinates
faceTransparencies
faceRoughness
faceMetallic

I don’t think the class with the problematic code requires any new includes to compile the problematic code.

The required includes are all already present and used by code elsewhere in the class.

It is such a strange annoying problem…

for now i have managed to avoid the errors by putting my code in a for loop like this

							for (int i1 = 0; i1 < 3; i1++)
							{
								byteBuffer->readFloat_16(faceTextureUCoordinates[i0].arr[i1], 2048);
							}

instead of

						byteBuffer->readFloat_16(faceTextureUCoordinates[i0].arr[0], 2048);
						byteBuffer->readFloat_16(faceTextureUCoordinates[i0].arr[1], 2048);
						byteBuffer->readFloat_16(faceTextureUCoordinates[i0].arr[2], 2048);

Today I had a similar issue keeping me busy for hours. I upgraded from UE4.27 to UE5.1 and building the code would fail on an engine file which could not find a certain header. After confirming that a clean project compiled just fine I had to debug the issue by removing code until the project compiled. It turned out that when one of my plugins referenced a certain engine header, the project would not build. no errors, no warnings, just that the engine itself failed to find one of its headers. The problem was that I had registered the wrong module for that header in my plugin’s Build.cs file because Epic documented the wrong module name in the docs (for UAnimationBlueprintLibrary).