Unreal Engine 4添加自定义Settings到项目设置

1.首先要创建个插件,不懂的看UE4 如何写插件

2.创建一个Uobject类,这里叫MySetting

.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once
#include "Engine.h"
#include "UObject/NoExportTypes.h"
#include "MySetting.generated.h"

/**
 * 
 */
UCLASS(config = MySetting)
class UMySetting : public UObject
{
	GENERATED_BODY()
public:
	UMySetting(const FObjectInitializer& obj);
	UPROPERTY(Config, EditAnywhere, Category = Settings)
		int32 SomeIntProperty;

	UPROPERTY(Config, EditAnywhere, Category = Settings)
		bool SomeBoolProperty;
	
	
};

.cpp

 

 

// Fill out your copyright notice in the Description page of Project Settings.

#include "TestPrivatePCH.h"
#include "MySetting.h"


UMySetting::UMySetting(const FObjectInitializer& obj)
{
	SomeIntProperty = 0;
	SomeBoolProperty = true;


}

3.然后在插件的cpp里添加头文件#include "ISettingsModule.h"和#include "MySetting.h"

 

4.在插件的StartupModule函数上注册写

	if (ISettingsModule* SettingModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
	{
		SettingModule->RegisterSettings("Project", "Plugins", "MySetting",
			LOCTEXT("RuntimeSettingsName", "My Setting Page"),
			LOCTEXT("RuntimeSettingsDescription", "Configure my setting"),
			GetMutableDefault<UMySetting>()
		);
	}

5.ShutdownModule()函数中解注册

    if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
    {
        SettingsModule->UnregisterSettings("Project", "Plugins", "MySetting");
    }

然后在项目设置里就能看到了

还有项目的Saved/Config/Windows下面发现创建了一个MySettings.ini的配置文件

第二种:使用UDeveloperSettings

.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Engine/DeveloperSettings.h"
#include "MyDeveloperSettings.generated.h"

USTRUCT(BlueprintType)
struct FLevelInfo
{
	GENERATED_BODY()
public:
	UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, config)
		int32 ID;
	UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, config)
		FName Name;
};

/**
 * 
 */
UCLASS(config=Game, defaultconfig)
class AAB_API UMyDeveloperSettings : public UDeveloperSettings
{
	GENERATED_BODY()
public:
	UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, config)
		TArray<FLevelInfo> Levels;

	UFUNCTION(BlueprintCallable)
		static UMyDeveloperSettings* GetMyDeveloperSettings();
};

.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "MyDeveloperSettings.h"

UMyDeveloperSettings* UMyDeveloperSettings::GetMyDeveloperSettings()
{
	UMyDeveloperSettings* Settings = GetMutableDefault<UMyDeveloperSettings>();
	return Settings;
}

PS:shipping包的ini文件在C:\Users\用户名\AppData\Local\MyProject\Saved\Config\WindowsNoEditor下

评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页