Unreal Engine: Difference between revisions

From Andreida
Line 33: Line 33:


= Links =
= Links =
* [https://www.youtube.com/watch?v=IaU2Hue-ApI The Unreal Engine Game Framework: From int main() to BeginPlay]
* [https://www.youtube.com/watch?v=IaU2Hue-ApI The Unreal Engine Game Framework: From int main() to BeginPlay (video)]
* [https://www.youtube.com/watch?v=JOJP0CvpB8w Multiplayer in Unreal Engine: How to Understand Network Replication]
* [https://www.youtube.com/watch?v=JOJP0CvpB8w Multiplayer in Unreal Engine: How to Understand Network Replication (video)]





Revision as of 04:45, 27 April 2024

Installation

 https://dotnet.microsoft.com/en-us/download/dotnet/3.1
 https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-3.1.32-windows-x64-installer
  • Visual Studio 2022: https://visualstudio.microsoft.com/downloads/
    • Workloads / Desktop development with C++ (was suggested by Visual Studio when I loaded a UE5 project)
    • Workloads / .NET desktop development (was suggested by Visual Studio when I loaded a UE5 project)
    • Workloads / Game Development with C++
      • don't unselect anything
      • Windows 10 SDK (1.0.20*)
      • Unreal Engine Test Adapter
      • Unreal Engine uproject support
    • Individual components / .NET 6.0 Runtime (Long Term Support) (was suggested by Visual Studio when I loaded a UE5 project)
    • Individual components / .NET Framework 4.8.1 SDK (or higher)
    • Individual components / .NET Framework 4.6.2 targeting pack (was suggested by Visual Studio when I loaded a UE5 project)
    • Individual components / MSVC 143 - VS 2022 C++ x64/x86 build tools (v14.36-17.6 or newer?) (was suggested by Visual Studio when I loaded a UE5 project)
    • After you install VS 2022, look in the VS Installer at the "Update" button. Enabled? DO NOT USE IT! (for now, or be prepared to use the rollback feature of the installer. I have NO idea if there is a certain version of VS 2022 needed to work properly with UE but I DO know that the Unreal Engine 5.3 is NOT usable without engine source changes if you have a fresh installation.)
  • Unreal Engine Visual Studio Integration Tool plugin: https://aka.ms/vsituemarketplace (repeat after new engine installation)
  • naming convention checker: ".editorconfig" parallel to your .uproject file.
    Content: https://raw.githubusercontent.com/microsoft/vc-ue-extensions/main/Source/.editorconfig
  • HLS configuration file: "shadertoolsconfig.json" parallel to your .uproject file.
    Content: automatically created, defaults to:
{
  "hlsl.preprocessorDefinitions": {
  },
  " hlsl.additionalIncludeDirectories": [
  ],
  "hlsl.virtualDirectoryMappings": {
  }
}

Links


Unreal Engine

Blender

  • Export Options (so that the object is not lying on the side after Export/Import):
    • Forward: Y Forward
    • Up: Z up
  • Changing the object's origin to its bottom:
    • Switch to Edit Mode if needed (Tab). With vertex selection on, choose the center vertex in the bottom. Press Shift+S and choose Cursor to Selected. The 3D cursor will move to the selected vertex. Deselect all and switch to Object Mode (Tab).
    • In Tools choose Set Origin and then Origin to 3D Cursor.
    • Make sure the object's coordinates are set to 0,0,0. Now the object should be placed properly on the XY plane.

C++

Variable names

If you want to use real variable names but have nice names in the UE editor too, then use meta/DisplayName

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, Meta = (DisplayName = "First Person Camera Component") )
    UCameraComponent* m_pFirstPersonCameraComponent;

owner / client /server

The instance that spawned the class is always ROLE_Authority. If an Actor is spawned on the client, the client is the authority. 
-- OmaManfred

OmaManfred::

 
And concerning the owner stuff:


When you spawn an instance of a class on the server FOR Client A, you have to set him as the owner.

FActorSpawnParameters params;
params.Owner = PlayerAPlayerController;

SpawnActor<Class>(Class:StaticClass(),params);

Then on Client B you can say IsOwner(PlayerBPlayerController), which should return false. 

Logging

The following is just a copy/paste/change from the UE4 wiki and was really done from different persons, I am just using the work of different people here. Put it in a Log.h and include it into your <your_project>.h file after the #include "Engine.h". Because <your_project>.h is in every of your files, you will now be able to use these macros in every .cpp file. If - like in certain newer UE projects - this is not working, because <your_project>.h is not included in most files, put the include of your Log.h in the headers of the .cpps where you want to use it.


#pragma once

#include "CoreMinimal.h"

// macros
// - LOG_LINE
// - LOG -> output log
// -- LOG("text");
// -- LOG("text %s %f %d", "text", 1.2, 5);
// - PRINT -> screen
// -- PRINT("text");
// -- PRINT("text %s %f %d", "text", 1.2, 5);

#if _MSC_VER
#define FUNC_NAME    TEXT(__FUNCTION__)
#else // FIXME - GCC?
#define FUNC_NAME    TEXT(__func__)
#endif

#define LOG_LINE UE_LOG(LogTemp, Warning, TEXT("%s, file: %s, line %d"), FUNC_NAME, *FString(__FILE__), __LINE__);
//#define LOG_NULL(s, p) UE_LOG(LogTemp, Warning, TEXT("pointer %s %s"),s, (p?TEXT("ok"):TEXT("null") ) );

#define PRINT(format, ...) \
{ \
	const FString sFunc = FString::Printf(TEXT("%s"), FUNC_NAME); \
	const FString sText = FString::Printf(TEXT(format), ##__VA_ARGS__); \
	const FString sMsg = FString::Printf(TEXT("%s() : %s"), *sFunc, *sText); \
	if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5, FColor::White, sMsg); \
}

#define LOG(format, ...) \
{ \
    const FString sMsg = FString::Printf(TEXT(format), ##__VA_ARGS__); \
    UE_LOG(LogTemp, Warning, TEXT("%s() : %s"), FUNC_NAME, *sMsg);\
}

Example Usage

LOG_LINE;
LOG("I am a line of text in the log,");
PRINT("but me, I am a line of text on the display screen, so there!");

There are examples with dynamic values in the code above. If you look carefully ... :-)

Custom Log

If you want your own selectable category in the log filter to be able to only show your log messages, then you have to

  • add this line in the Log.h above any defines:
DECLARE_LOG_CATEGORY_EXTERN(aProjectLog, Log, All);
  • replace all "LogTemp" with "aProjectLog"
  • add this line to each .cpp where you want to use these macros:
DEFINE_LOG_CATEGORY(aProjectLog);

Am I client or server ?

https://answers.unrealengine.com/questions/416305/how-to-know-if-listenserverclient-owner-for-rpc.html

To answer questions 1 and 2: you can use AActor::GetNetMode() 
which returns whether you are a listen server, dedicated server or network client.

         if (GetNetMode() == ENetMode::NM_ListenServer)
         {
         }
         

The ENetMode values are:

    NM_Standalone = 0

    NM_DedicatedServer = 1

    NM_ListenServer = 2

    NM_Client = 3 // is only when you are actually connected to a server

The ordering of the ENetMode values allows you to check multiple things at once: 
GetNetMode() <= 2 means you are the server or standalone, so you have 'global authority'.

UMG with C++ base class

  • create a normal UMG widget
  • create a C++ class with base class UserWidget (UUserWidget)
  • build the project
  • set the parent class of the UMG widget to your C++ class
  • in <Project>.Build.cs add "UMG", "SLATE", "SLATECORE":
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG" });

		PrivateDependencyModuleNames.AddRange(new string[] {  });

		// Uncomment if you are using Slate UI
		 PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
  • put into <Project>.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"

SLATE

https://wiki.unrealengine.com/Slate_Introduction_%E2%80%92_Basic_Menu_Part_1

The "canvas" in UMG is "SConstraintCanvas" in Slate.

Multiplayer / Sessions

Do not search for "multiplayer", search for "sessions". Good tutorial: https://wiki.unrealengine.com/How_To_Use_Sessions_In_C%2B%2B

This is a Youtube video I found which gives you an overview, so you already have an idea how it works before you start learning the details: Multiplayer in Unreal Engine: How to Understand Network Replication.

String conversions

from: https://docs.unrealengine.com/en-us/Programming/UnrealArchitecture/StringHandling/FString

FString TestHUDString = FString(TEXT("This is my test FString."));
FName TestHUDName = FName(*TestHUDString);
FText TestHUDText = FText::FromString(TestHUDString);

UE Editor

Escape key stops simulation in editor

If you want to change this behavior, open "Edit/Editor Preferences" and search for "stop". Then change under "Play World/Stop" the shortcut "Escape" to whatever you want, for example shift-Escape.

Details/Text/Line-Break

If you are shown a text in the Details tab, chances are you can use shift-return to create a line break.

Removing projects from "Project Open" dialog

Open (use the correct engine version)

%USERPROFILE%\AppData\Local\UnrealEngine\5.3\Saved\Config\WindowsEditor\EditorSettings.ini

and modify/remove

CreatedProjectPaths
RecentlyOpenedProjectFiles

Volume of Sound after building in Visual Studio

  • Content Drawer / Settings / Show Engine Content
  • Engine / Content / EditorSounds / Notifications / *_Cue
  • Volume Multiplier

Misc

Source control

Don't use Mercurial (or git) for game development. That would be just plain stupid.
Use Subversion or something like that.

The minimum you have to put under source control:

/Config
/Content
/Source
Project.uproject

Depending on your project:

/.editorconfig
/shadertoolsconfig.json


For ignores, have a look at ignoring files with svn.

Under "Content" you will probably after some time see "EXTERNAL_ACTOR" or stuff like that. These are your map in parts, so multiple people can work on different parts of the map at the same time. That is the theory I read. :-)

So, no, don't delete them. If you don't want them (and their advantages), then switch from "World Partitioning" to "World Composition" for levels like it was used in UE4. Where/how? No idea. When I google for it I only find stuff like "you should not be using UE5 for production at this time". Perhaps the posts are old? No idea. Again.

Developer Folder

If you have the developer folder(s) enabled "Content / View Options / Show Developers Content" then make sure to not reference it from outside when cooking a project.

Other Licenses (examples)

not allowed

  • GNU General Public License (GPL),
  • Lesser GPL (LGPL) (unless you are merely dynamically linking a shared library), or
  • Creative Commons Attribution-ShareAlike License.

Code or content under the following licenses, for example, are allowed

  • BSD License,
  • MIT License,
  • Microsoft Public License, or
  • Apache License.

Visual Studio

Show errors after build

Tools / Options / Projects and Solutions / Always show Error List if build finishes with errors

Can't build Solution

  • UE / Edit / Editor Preferences / Live Coding / Enable Life Coding: disable
  • Use the context menu on your project and select "Set as Startup Project".
  • Use "Build <project> (ctrl-B) to build.

This works for me but I am pretty sure there should be a way to have "Live Coding" enabled AND build from Visual Studio. I mean... the UE developers will themselves want to have both options, right? So it should be possible?

Update: I found out that I have to fix the errors in the other (there are ca. 7) projects in the solution to be able to build the solution and to do that I'd have to get the source version of UE. Currently I am very unhappy with all this. A UE5 installation on top of a functioning UE4 installation works. But if you only install UE 5.3 onto a new system, not working :-(

Generate Visual Studio Project file

To get a cleaner project you could create a "delete-temps.cmd" with content like the following (match it with your needs):

rmdir /s /q .vs
rmdir /s /q Binaries
rmdir /s /q DerivedDataCache
rmdir /s /q Intermediate
rmdir /s /q Saved
del *.sln

After you cleaned away the trash you can right-click your *.uproject file and select "Generate Visual Studio Project file". This might remove some problems. Or create new ones. So far it only helped me, but it IS a bit brutal, right?

Other

Black Screens or flickering/invisible new action popup

Disable multiplane overlay

Errors

Visual Studio

cannot open source file "CoreMinimal.h"

Error List: "Build + Intelli Sense" => "Build Only"

(source)

I am pretty sure this is NOT a solution but a workaround.