メモ

CG 関連、ゲームエンジン関連メモ

Config に任意の値を設定して Blueprint で読み込む

  • config の格納場所

    • <プロジェクトルート>\Config 配下
  • Config の種類

    • DefaultEditor.ini
    • DefaultEditorPerProjectUserSettings.ini
    • DefaultEngine.ini
    • DefaultGame.ini
    • DefaultInput.ini
  • Config のカテゴリ

    • 全般
      • Engine
      • Game
      • Input
      • DeviceProfiles
      • GameUserSettings
      • Scalability
      • RuntimeOptions
      • InstallBundle
      • Hardware
      • GameplayTags
    • エディタのみ
      • Editor
      • EditorPerProjectUserSettings
      • EditorSettings
      • EditorKeyBindings
      • EditorLayout
    • デスクトップのみ
      • Compat
      • Lightmass

Visual Studio での配置場所

  • Games/<プロジェクト名>/Config 配下

Blueprint から config の任意の値を呼び出す方法

  • 適当なアクターを作成する

    • C++ Classes > 右クリック > Add C++ Class …
    • Actor クラスを親に設定する
  • ヘッダファイル

    • UCLASS に Config のカテゴリを設定する
    • UPROPERTY に Config 、BlueprintReadOnly を指定する
      • このクラスの関連する config 上の値を読み込むようにする
      • Blueprint 上で読み込みができるようにする
// ConfigActor.h

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ConfigActor.generated.h"

UCLASS(Config = Game) // <= Config のカテゴリを指定する
class HTTPREQUESTSAMPLE_API AConfigActor : public AActor
{
    GENERATED_BODY()

public:
    // Sets default values for this actor's properties
    AConfigActor();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:
    // Called every frame
    virtual void Tick(float DeltaTime) override;

    UPROPERTY(Config, BlueprintReadOnly) // <= Config, Blueprint 読み込み設定
    int Value1;

    UPROPERTY(Config, BlueprintReadOnly) // <= Config, Blueprint 読み込み設定
    FString Value2;
};
  • config に任意の値を追加する (今回は DefaultGame.ini を対象)
    • section ([] で括られた部分) は以下のように指定する
      • /<作成したクラスまでのパス>/<プロジェクト名>.<クラス名>
      • [/Script/HttpRequestSample.ConfigActor]
; DefaultGame.ini

[/Script/EngineSettings.GeneralProjectSettings]
ProjectID=ECD3E9DE4FA3F0986CAD50850CAD6E64
ProjectName=Third Person Game Template

; 任意値の追加
[/Script/HttpRequestSample.ConfigActor]
Value1=1
Value2="test"
  • 作成した C++ クラス (ConfigActor) を継承した Blueprint クラスを生成する

    • Content Browser > C++ Classes >対象 C++ > MRB (右クリック) > Create Blueprint class based on ConfigActor
  • 生成した Blueprint クラスを任意の level に配置

  • Config の任意の値が読み込まれるか確認する

  • Blueprint クラスを編集
    • Event Graph
      • Blueprint の要素表示設定から継承したクラスの変数を表示するように変更
        • (ギアアイコン) > Show Inherited Variable
        • 継承元 Config Actor の変数を表示
      • プレイ時に読み込むようにする
        • Event BeginPlay のピンのあとに、Print String を呼び出す
        • それぞれの Config の値を In String に設定する

- レベルのゲームプレイ設定を変更する - Standalone Game

  • それぞれの値が読み込まれていることを確認
    • Value1 = 1
    • Value2 = test

参考

コンフィギュレーション ファイル

クラス指定子

プロパティ

https://www.youtube.com/watch?v=QQH0y_5NU3Y

[UE4] 「エディタの環境設定」や「プロジェクト設定」に項目を追加する|株式会社ヒストリア