caseymcc / UE4CMake

Provides a simple way to add a cmake lib to any Unreal Engine 4 (UE4) or 5 (UE5) project.
MIT License
78 stars 14 forks source link

Can't get this working in UE5.1 #11

Closed Travistyse closed 1 year ago

Travistyse commented 1 year ago

I've tried using this as a reference: https://github.com/caseymcc/UE4_FastNoise2 I've tried using Bing's version of ChatGPT for help. I just can't get this working at all after 8 hours. I have lost my mind.

I've been using VS 2022 with Unreal just fine with no issues with the portable version of FastNoise but need to upgrade for performance reasons. The UE4_FastNoise2 example gives me this error:

error CS0117: 'WindowsCompiler' does not contain a definition for 'VisualStudio2017'

But I've installed the build tools for 2017 to no success.

While trying to use this (UE4CMake) project on its own without taking the other project (UE4_FastNoise2) into account, I.. will try to recap what I've done but it's been a long time under stress.

I made this Cmakelists.txt file in the root directory of my project:


cmake_minimum_required(VERSION 3.10)
project(VoxelSurvivalGame VERSION 1.0)

set(UE4_ROOT "C:/Program Files/Epic Games/UE_5.1")
set(UE4_PROJECT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
set(UE4_PROJECT_NAME "${PROJECT_NAME}")
set(UE4_PROJECT_FILE "${UE4_PROJECT_ROOT}/${UE4_PROJECT_NAME}.uproject")
set(UE4_PROJECT_BUILD_FILE "${UE4_PROJECT_ROOT}/Source/${UE4_PROJECT_NAME}.Target.cs")
set(UE4_PROJECT_BUILD_CONFIG "Development")
set(UE4_PROJECT_BUILD_PLATFORM "Win64")
set(UE4_PROJECT_BUILD_ARGS "-rocket -progress")

include("UE4CMake/UE4CMake.cmake")

set(FASTNOISE2_ROOT "D:/Projects\Unreal/VoxelSurvivalGame/FastNoise2")
set(FASTNOISE2_INCLUDE_DIR "${FASTNOISE2_ROOT}/include")
set(FASTNOISE2_LIBRARY_DIR "${FASTNOISE2_ROOT}/lib")

add_subdirectory("${FASTNOISE2_ROOT}")

file(GLOB_RECURSE UE4_PROJECT_SOURCE_FILES "${UE4_PROJECT_ROOT}/Source/*.cpp" "${UE4_PROJECT_ROOT}/Source/*.h")
add_executable(${UE4_PROJECT_NAME} ${UE4_PROJECT_SOURCE_FILES})

target_include_directories(${UE4_PROJECT_NAME} PRIVATE ${FASTNOISE2_INCLUDE_DIR})
target_link_libraries(${UE4_PROJECT_NAME} PRIVATE FastNoise2)
target_link_libraries(${UE4_PROJECT_NAME} PRIVATE UE4)

I placed a folder named FastNoise2 in the root of my project, inside is everything from the github (cmake, include, NoiseTool, src...)

I placed a folder named Plugins inside of my root and added the CMakeTarget folder with Source, CMakeTarget.uplugin inside

In my root is a CMakeTarget.build.cs file that I didn't modify in any way

And my .uProject is:

{
    "FileVersion": 3,
    "EngineAssociation": "5.1",
    "Category": "",
    "Description": "",
    "Modules": [
        {
            "Name": "VoxelSurvivalGame",
            "Type": "Runtime",
            "LoadingPhase": "Default",
            "AdditionalDependencies": [
                "Engine"
            ]
        },
        {
            "Name": "FastNoise2",
            "Type": "Runtime",
            "LoadingPhase": "Default"
        }
    ],
    "Plugins": [
        {
            "Name": "CMakeTarget",
            "Type": "Runtime",
            "Enabled": true
        },
        {
            "Name": "ModelingToolsEditorMode",
            "Type": "Runtime",
            "Enabled": true,
            "TargetAllowList": [
                "Editor"
            ]
        }
    ]
}

Attempting to generate my project files grants me this error:

Running C:/Program Files/Epic Games/UE_5.1/Engine/Build/BatchFiles/Build.bat  -projectfiles -project="D:/Projects/Unreal/VoxelSurvivalGame/VoxelSurvivalGame.uproject" -game -rocket -progress -log="D:\Projects\Unreal\VoxelSurvivalGame/Saved/Logs/UnrealVersionSelector-2023.03.11-21.23.17.log"
Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" -projectfiles -project="D:/Projects/Unreal/VoxelSurvivalGame/VoxelSurvivalGame.uproject" -game -rocket -progress -log="D:\Projects\Unreal\VoxelSurvivalGame/Saved/Logs/UnrealVersionSelector-2023.03.11-21.23.17.log"
Log file: D:\Projects\Unreal\VoxelSurvivalGame\Saved\Logs\UnrealVersionSelector-2023.03.11-21.23.17.log
Log file: C:\Users\Travi\AppData\Local\UnrealBuildTool\Log_GPF.txt
Discovering modules, targets and source code for project...
D:\Projects\Unreal\VoxelSurvivalGame\Plugins\CMakeTarget\Source\CMakeTarget.Build.cs(247,30): error CS0117: 'WindowsCompiler' does not contain a definition for 'VisualStudio2017'
D:\Projects\Unreal\VoxelSurvivalGame\Plugins\CMakeTarget\Source\CMakeTarget.Build.cs(262,41): error CS0117: 'WindowsCompiler' does not contain a definition for 'VisualStudio2017'
D:\Projects\Unreal\VoxelSurvivalGame\Plugins\CMakeTarget\Source\CMakeTarget.Build.cs(264,52): error CS0117: 'WindowsArchitecture' does not contain a definition for 'x86'
D:\Projects\Unreal\VoxelSurvivalGame\Plugins\CMakeTarget\Source\CMakeTarget.Build.cs(268,57): error CS0117: 'WindowsArchitecture' does not contain a definition for 'ARM32'
Expecting to find a type to be declared in a target rules named 'FastNoise2ExampleTarget'.  This type must derive from the 'TargetRules' type defined by Unreal Build Tool.

I'm using UE5 5.1 and don't know any other way of getting FastNoise2 working in C++ outside of this project. I'm expecting that I'm doing something wrong but there's just not enough information and attempting to learn from the example project and follow Ai instructions has left me very very much at wits end.

Oh, and I also placed, inside of the Source folder in the root directory, the Deps and FastNoise2Example folders, FastNoise2Example.Target.cs, and FastNoise2ExampleEditor.Target.cs

caseymcc commented 1 year ago

VS2017 and 32bit support have been removed form UE5+. The latest version of UE4CMake has pre processors for them however I do not believe I have update the FastNoise example for the latest version of UE4CMkake. The easiest thing for you is just to go to the UE4_FastNoise2)/Plugins/CMakeTarget and pull the latest, however you will have to change the CMakeTarget folder name to UE4CMake. I will update the example in a few.

caseymcc commented 1 year ago

I updated it for UE5, https://github.com/caseymcc/UE4_FastNoise2/tree/ue5_1 . Need to fix some items on linux before I can merge it but you should be able to use that branch for Windows.

caseymcc commented 1 year ago

Also someone brought fastnoise2 in as a blueprint, not sure which version it is using but here it is, https://github.com/DoubleDeez/UnrealFastNoise2

Travistyse commented 1 year ago

Thanks so much! And I saw the blueprint option but for performance reasons needed to be able to access everything in C++ and on a separate thread. I don't typically work with plugins or libraries as I've been able to code everything myself up until this point so I don't entirely understand how they all work together within Unreal. Honestly, I'm not even all that familiar with Cmake. But I'll test this out when I wake up - I've been dealing with long covid so I'm sleeping long and weird hours lately while I recover. I really appreciate you. I could not for the life of me figure this out. I'd close this but am not sure if you wanted to add a post for Linux support or whatever - but it's also a different github repo so.. I'll let you decide.

caseymcc commented 1 year ago

I will close it, merged a fix for linux so the main branch should be good now.