UE5.4.0-preview-1: C2248 'TMemoryWriterBase<TSizedDefaultAllocator<32>>::IndexSize': cannot access private member declared in class 'TMemoryWriterBase<TSizedDefaultAllocator<32>>'

I just downloaded and compiled the new UE5.4.0-preview-1 and upgraded one of my 5.3.2 projects.
I now get some errors from BufferArchive.h that I have never seen before.
I did not change anything to my code or the Engine code.
This was all working fine with UE5.3.2.

Here are the errors:

12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\BufferArchive.h(17): error C2248: 'TMemoryWriterBase<TSizedDefaultAllocator<32>>::IndexSize': cannot access private member declared in class 'TMemoryWriterBase<TSizedDefaultAllocator<32>>'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\MemoryWriter.h(23): note: see declaration of 'TMemoryWriterBase<TSizedDefaultAllocator<32>>::IndexSize'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\MemoryWriter.h(94): note: see declaration of 'TMemoryWriterBase<TSizedDefaultAllocator<32>>'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\BufferArchive.h(48): note: see reference to class template instantiation 'TBufferArchive<32>' being compiled
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\BufferArchive.h(17): error C2338: static_assert failed: 'Only 32-bit and 64-bit index sizes supported'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\BufferArchive.h(20): error C2248: 'TMemoryWriterBase<TSizedDefaultAllocator<32>>::IndexSize': cannot access private member declared in class 'TMemoryWriterBase<TSizedDefaultAllocator<32>>'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\MemoryWriter.h(23): note: see declaration of 'TMemoryWriterBase<TSizedDefaultAllocator<32>>::IndexSize'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\MemoryWriter.h(94): note: see declaration of 'TMemoryWriterBase<TSizedDefaultAllocator<32>>'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\BufferArchive.h(17): error C2248: 'TMemoryWriterBase<TSizedDefaultAllocator<64>>::IndexSize': cannot access private member declared in class 'TMemoryWriterBase<TSizedDefaultAllocator<64>>'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\MemoryWriter.h(23): note: see declaration of 'TMemoryWriterBase<TSizedDefaultAllocator<64>>::IndexSize'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\MemoryWriter.h(94): note: see declaration of 'TMemoryWriterBase<TSizedDefaultAllocator<64>>'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\BufferArchive.h(56): note: see reference to class template instantiation 'TBufferArchive<64>' being compiled
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\BufferArchive.h(20): error C2248: 'TMemoryWriterBase<TSizedDefaultAllocator<64>>::IndexSize': cannot access private member declared in class 'TMemoryWriterBase<TSizedDefaultAllocator<64>>'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\MemoryWriter.h(23): note: see declaration of 'TMemoryWriterBase<TSizedDefaultAllocator<64>>::IndexSize'
12>E:\UE\UnrealEngine5.4.0\Engine\Source\Runtime\Core\Public\Serialization\MemoryWriter.h(94): note: see declaration of 'TMemoryWriterBase<TSizedDefaultAllocator<64>>'

Any clue what’s causing this?
Win 11, VS 2022

Thanks so much,
Sebastian

4 Likes

So the static_assert in TBufferArchive wants to use the template parameter , and coincidentally in the base class TMemoryWriterBase there is a private static variable named IndexSize, which it instead tries to take (and can’t because it’s private).

Since that variable is private, it should only be used in this class, so we can rename all occurances of “IndexSize” in memorywriter.h to something else (IndexSizeX or whatever), then the static_assert will end up taking the template-parameter instead of the variable.

3 Likes

Hi @kalmiya,
Thanks for your response, and sorry for my delay in getting back to you.
This fixed the error. Thanks so much.

2 Likes

(post deleted by author)

2 Likes

(post deleted by author)

2 Likes

What if it is the launcher version of UE5.4?what should i do…

2 Likes

I have same problem but I need a solution where I won’t have to modify the source code.

1 Like

For my project solved by Including “LevelEditor.h” instead of “UnrealEd.h”

1 Like

This appears to be a serious bug with the 5.4.0 code release that Epic needs to fix ASAP.

I’m hitting this as well. Upgraded my project to 5.4, and now I hit this error when compiling Shipping.

More info:

  • My project uses a built-from-source version of the Engine, but it is an unmodified 5.4 Engine build.
  • The Engine build does not hit this error.
  • I only see this error when building my project in Shipping configuration.
1 Like

same problem for me ,I solved it by check and update the build setting on my build.target.cs file
make sure use the latest build settings,hope this will help

DefaultBuildSettings = BuildSettingsVersion.Latest;

this will recompile your project and relavent engine modules ,it will take some time,but requires no source code changing

2 Likes

last time i was using V2 which is ue5.2 build setting

1 Like

Nice find @mactavisher ! This works!

For anyone struggling with this, this is the way to resolve your issue.

For future reference for Epic: This is still absolutely a bug with the 5.4.0 release. In my opinion the solution above should be considered a workaround. The code in question is ambiguous and it is not a surprise that it fails with certain compiler settings.


not very sure if this is a bug ,but epic tweaks some of the setting in each version,like cpp standards upgrades and code style check,they also mentioned that settings will cause some compile issues ,so just stick to their latest will make it easier :grin: