您的位置:首页 > 编程语言 > C语言/C++

ue4框架C++语法汇总文章

2016-11-08 11:03 232 查看
1.Run external .exe file

TCHAR* url = TEXT("C:\\windows\\system32\\calc.exe");
FPlatformProcess::CreateProc(url, nullptr, true, false, false, nullptr, 0, nullptr, nullptr);

//If you want to open .exe file with some params
FPlatformProcess::CreateProc(url, TEXT("-MyFlag -FULLSCREEN"), true, false, false, nullptr, 0, nullptr, nullptr);


external:

Check Runtime Params, infomation source url: https://answers.unrealengine.com/questions/123559/can-we-make-command-line-arguments.html

if (FParse::Param(FCommandLine::Get(), TEXT("MyFlag")))
{
return true;
}
else
{
return false;
}


2.Create UMG widget and AddToView

if (!IsValid(MainMenuRef))
{
MainMenuRef = CreateWidget<UUserWidget>(this, MainMenuWB);
}
MainMenuRef->AddToViewport(0);
APlayerController* LocalPlayerController = UGameplayStatics::GetPlayerController(GetWorld(),0);
LocalPlayerController->bShowMouseCursor = true;


3.C++ PrintString On Screen

GEngine->AddOnScreenDebugMessage()


4.FString Conver to TCHAR

FString testStr = TEXT("Hello World");
const TCHAR* MyTchar= *testStr;


5.Get Runtime Path, more infomation, https://answers.unrealengine.com/questions/514739/get-the-abolute-game-path.html

FString pathPart1 = FPlatformProcess::BaseDir();
FString appPath = pathPart1  + "/MySteamOnlineC.exe"; //The 'SteamOnlineC.exe' is my project entry file after package.


6.OnlineSystem DefaultEngine.ini config, found the file with path, UnrealProjectDirectory/ProjectName/Config/DefaultEngine.ini

LAN and Normal

[OnlineSubsystem]
DefaultPlatformService=Null


Run on Steam

[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")

[OnlineSubsystem]
DefaultPlatformService=Steam

[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=480
bVACEnabled=0

[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"


7. How to get TSubclassOf<AActor> type from class instance, for example ,GetAllActorsOfClass

TArray<AActor*> cameraArray;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ACameraManager::StaticClass(), cameraArray);


8. Collision box add event bind, add beginOverlap Event.

BoxCollision->OnComponentBeginOverlap.AddDynamic(this, &ABossRunCharacter::LaunchEnemy);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: