LoginSignup
2
2

More than 5 years have passed since last update.

Assetの配列を取得する

Posted at

Assetの配列を取得する

公式ドキュメント

アセットの参照
https://docs.unrealengine.com/latest/JPN/Programming/Assets/ReferencingAssets/index.html

オブジェクトの検索 / ロード

AFunctionalTest* TestToRun = FindObject<AFunctionalTest>(TestsOuter, *TestName);
GridTexture = LoadObject<UTexture2D>(NULL, TEXT("/Engine/EngineMaterials/DefaultWhiteGrid.DefaultWhiteGrid"), NULL, LOAD_None, NULL);

アセットをパス指定で取得することが出来ることを知った。

Texture2Dの配列を作成する

300枚のTextureをインポートする
image

マテリアルを作成する
Textureを変更できるように、TextureSampleParameter2Dを使用する
image

Planeを追加する。
作成したマテリアルを設定する
image

レベルブループリントを編集する
変数:Texturesの配列分、毎フレームごとにTextureを変更する

変数名 変数の型
Material Material Instance Dynamic(リファレンス)
Textures Texture2D(リファレンス)の配列
Count Integer

image

Texturesのデフォルト値を300枚設定すればいいが、さすがにつらい
image

AssetからTexture2Dの配列を取得するBlueprintFunctionLibraryを作成する

BlueprintFunctionLibraryの作成方法は以下を参照
http://qiita.com/gansaibow/items/7dee2f3d61af9bd8b37f

GetAssetArray.h

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

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "GetAssetArray.generated.h"

/**
 * 
 */
UCLASS()
class GETASSETSARRAY_API UGetAssetArray : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:

    UFUNCTION(BlueprintCallable, Category = "MyBPLibrary")
    static TArray<UTexture2D *> GetTexture2D();

};

GetAssetArray.cpp

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

#include "GetAssetsArray.h"
#include "GetAssetArray.h"

TArray<UTexture2D *> UGetAssetArray::GetTexture2D()
{
    TArray<UTexture2D *> texture2Ds;

    FString base = "/Game/Textures/image_";
    for (int i = 1; i <= 300; i++)
    {
        FString no = FString::Printf(TEXT("%03d"), i);

        FString tmpPath = base + no;
        UTexture2D * texture = LoadObject<UTexture2D>(NULL, *tmpPath, NULL, LOAD_None, NULL);
        texture2Ds.Add(texture);
    }
    return texture2Ds;
}

AssetのTexture2Dの配列を取得して、Texturesに設定する
image

実行すると画像の連番が毎フレーム書き換えられる

C++でAssetを取得できる方法が分かったので、配列をEditorで1個1個設定しなくて済む 動画を静止画連番に書き出して、Textureの連番を毎フレーム書き換えて動画を再現するとか簡単に出来る #UE4Study pic.twitter.com/gpnrFVxWhz

— GAN彩坊(光の戦士) (@gansaibow) 2017年3月27日

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2