Sorry for all the large images, it seems the forum doesn’t support resizing or spoiler button tags.
I’m still having no luck with UE4.12 or a fresh project. This is what I’m doing, perhaps I’m doing something wrong.
- New project - C++ - Third Person
- Open "ProjectName.Build.cs - add “RHI” to dependencies.
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class MyProject2 : ModuleRules
{
public MyProject2(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "RHI" });
}
}
- Build Project
Now these are the 2 different routes I have tried for the BP Function library, both in fresh new projects.
- Right click PROJECTNAME folder in Visual Studio - Add - Class - C++ Class.
2. Add code to Header.
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "UBpVideoSettingsLib.generated.h"
#define MIN_SCREEN_WIDTH 1024
#define MIN_SCREEN_HEIGHT 768
/**
* Custom Blueprint Function Library.
*/
UCLASS()
class MYPROJECT_API UBpVideoSettingsLib : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
// Get a list of screen resolutions supported on this machine
UFUNCTION(BlueprintPure, Category = "Video Settings")
static bool GetSupportedScreenResolutions(TArray<FString>& Resolutions);
// Get currently set screen resolution
UFUNCTION(BlueprintPure, Category = "Video Settings")
static FString GetScreenResolution();
// Check whether or not we are currently running in fullscreen mode
UFUNCTION(BlueprintPure, Category = "Video Settings")
static bool IsInFullscreen();
// Set the desired screen resolution (does not change it yet)
UFUNCTION(BlueprintCallable, Category = "Video Settings")
static bool SetScreenResolution(const int32 Width, const int32 Height, const bool Fullscreen);
// Change the current screen resolution
UFUNCTION(BlueprintCallable, Category = "Video Settings")
static bool ChangeScreenResolution(const int32 Width, const int32 Height, const bool Fullscreen);
// Get the current video quality settings
UFUNCTION(BlueprintCallable, Category = "Video Settings")
static bool GetVideoQualitySettings(int32& AntiAliasing, int32& Effects, int32& PostProcess, int32& Resolution, int32& Shadow, int32& Texture, int32& ViewDistance);
// Set the quality settings (not applied nor saved yet)
UFUNCTION(BlueprintCallable, Category = "Video Settings")
static bool SetVideoQualitySettings(const int32 AntiAliasing = 3, const int32 Effects = 3, const int32 PostProcess = 3,
const int32 Resolution = 100, const int32 Shadow = 3, const int32 Texture = 3, const int32 ViewDistance = 3);
// Check whether or not we have vertical sync enabled
UFUNCTION(BlueprintPure, Category = "Video Settings")
static bool IsVSyncEnabled();
// Set the vertical sync flag
UFUNCTION(BlueprintCallable, Category = "Video Settings")
static bool SetVSyncEnabled(const bool VSync);
// Confirm and save current video mode (resolution and fullscreen/windowed) as well as quality settings
UFUNCTION(BlueprintCallable, Category = "Video Settings")
static bool SaveVideoModeAndQuality();
// Revert to original video settings
UFUNCTION(BlueprintCallable, Category = "Video Settings")
static bool RevertVideoMode();
private:
// Try to get the GameUserSettings object from the engine
static UGameUserSettings* GetGameUserSettings();
};
- Add code to CPP
#include"MyProject2.h"
#include "UBpVideoSettingsLib.h"
// Get a list of screen resolutions supported by video adapter
// NOTE: This function needs "RHI" to be added to <Project>.Build.cs file!
bool UBpVideoSettingsLib::GetSupportedScreenResolutions(TArray<FString>& Resolutions)
{
FScreenResolutionArray ResolutionsArray;
if (RHIGetAvailableResolutions(ResolutionsArray, true)) // needs the "RHI" dependency
{
for (const FScreenResolutionRHI& Resolution : ResolutionsArray)
{
if (Resolution.Width < MIN_SCREEN_WIDTH || Resolution.Height < MIN_SCREEN_HEIGHT)
{
continue;
}
FString Str = FString::FromInt(Resolution.Width) + "x" + FString::FromInt(Resolution.Height);
Resolutions.AddUnique(Str);
}
return true;
}
return false; // failed to obtain screen resolutions
}
// Get currently set screen resolution
FString UBpVideoSettingsLib::GetScreenResolution()
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return FString("");
}
FIntPoint Resolution = Settings->GetScreenResolution();
return FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y);
}
// Check whether or not we are currently running in fullscreen mode
bool UBpVideoSettingsLib::IsInFullscreen()
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return false;
}
return Settings->GetFullscreenMode() == EWindowMode::Fullscreen;
}
// Set the desired screen resolution (does not change it yet)
bool UBpVideoSettingsLib::SetScreenResolution(const int32 Width, const int32 Height, const bool Fullscreen)
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return false;
}
Settings->SetScreenResolution(FIntPoint(Width, Height));
Settings->SetFullscreenMode(Fullscreen ? EWindowMode::Fullscreen : EWindowMode::Windowed);
return true;
}
// Change the current screen resolution
bool UBpVideoSettingsLib::ChangeScreenResolution(const int32 Width, const int32 Height, const bool Fullscreen)
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return false;
}
EWindowMode::Type WindowMode = Fullscreen ? EWindowMode::Fullscreen : EWindowMode::Windowed;
Settings->RequestResolutionChange(Width, Height, WindowMode, false);
return true;
}
// Get the current video quality settings
bool UBpVideoSettingsLib::GetVideoQualitySettings(int32& AntiAliasing, int32& Effects, int32& PostProcess,
int32& Resolution, int32& Shadow, int32& Texture, int32& ViewDistance)
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return false;
}
AntiAliasing = Settings->ScalabilityQuality.AntiAliasingQuality;
Effects = Settings->ScalabilityQuality.EffectsQuality;
PostProcess = Settings->ScalabilityQuality.PostProcessQuality;
Resolution = Settings->ScalabilityQuality.ResolutionQuality;
Shadow = Settings->ScalabilityQuality.ShadowQuality;
Texture = Settings->ScalabilityQuality.TextureQuality;
ViewDistance = Settings->ScalabilityQuality.ViewDistanceQuality;
return true;
}
// Set the quality settings (not applied nor saved yet)
bool UBpVideoSettingsLib::SetVideoQualitySettings(const int32 AntiAliasing, const int32 Effects, const int32 PostProcess,
const int32 Resolution, const int32 Shadow, const int32 Texture, const int32 ViewDistance)
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return false;
}
Settings->ScalabilityQuality.AntiAliasingQuality = AntiAliasing;
Settings->ScalabilityQuality.EffectsQuality = Effects;
Settings->ScalabilityQuality.PostProcessQuality = PostProcess;
Settings->ScalabilityQuality.ResolutionQuality = Resolution;
Settings->ScalabilityQuality.ShadowQuality = Shadow;
Settings->ScalabilityQuality.TextureQuality = Texture;
Settings->ScalabilityQuality.ViewDistanceQuality = ViewDistance;
return true;
}
// Check whether or not we have vertical sync enabled
bool UBpVideoSettingsLib::IsVSyncEnabled()
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return false;
}
return Settings->IsVSyncEnabled();
}
// Set the vertical sync flag
bool UBpVideoSettingsLib::SetVSyncEnabled(const bool VSync)
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return false;
}
Settings->SetVSyncEnabled(VSync);
return true;
}
// Confirm and save current video mode (resolution and fullscreen/windowed)
bool UBpVideoSettingsLib::SaveVideoModeAndQuality()
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return false;
}
Settings->ConfirmVideoMode();
Settings->ApplyNonResolutionSettings();
Settings->SaveSettings();
return true;
}
// Revert to original video settings
bool UBpVideoSettingsLib::RevertVideoMode()
{
UGameUserSettings* Settings = GetGameUserSettings();
if (!Settings)
{
return false;
}
Settings->RevertVideoMode();
return true;
}
//---- PRIVATE METHODS -------------------------------------------------------------------------------
// Try to get the GameUserSettings object from the engine
UGameUserSettings* UBpVideoSettingsLib::GetGameUserSettings()
{
if (GEngine != nullptr)
{
return GEngine->GameUserSettings;
}
return nullptr;
}
- Build Solution. No errors.
- Compile in editor. Compile Complete with no errors.
- Can’t call new functions in a blueprint within the editor.
- Relaunch editor - Still not able to call functions.
Second way of creating the BP function library.
- In the editor - File - Add C++ Class - BluePrintFunctionLibrary
2. Add code to Header.
3. Add code to CPP.
4 Build solution. - Compile errors.
That’s as far as I’ve got, I must be doing something wrong but I’ve no idea what it is. Hopefully this long list will help identify exactly what it is.