Unreal Engine: Difference between revisions
From Andreida
m (→Logging) |
(→C++) |
||
Line 88: | Line 88: | ||
} |
} |
||
</pre> |
|||
=== Am I client or server ? === |
|||
https://answers.unrealengine.com/questions/416305/how-to-know-if-listenserverclient-owner-for-rpc.html |
|||
<pre> |
|||
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'. |
|||
</pre> |
</pre> |
||
Revision as of 09:02, 13 May 2016
Currently using UE4 (4.10.4)
Links
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 before 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.
#pragma once #include "Log.h" #include "Engine.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);\ }
Am I client or server ?
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'.
Misc
Source control
The minimum you have to put under source control:
/Config /Content /Source Project.uproject