Assetの配列を取得する
C++でAssetを取得できる方法が分かったので、配列をEditorで1個1個設定しなくて済む 動画を静止画連番に書き出して、Textureの連番を毎フレーム書き換えて動画を再現するとか簡単に出来る #UE4Study pic.twitter.com/gpnrFVxWhz
— GAN彩坊(光の戦士) (@gansaibow) 2017年3月27日
公式ドキュメント
アセットの参照
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の配列を作成する
マテリアルを作成する
Textureを変更できるように、TextureSampleParameter2Dを使用する
レベルブループリントを編集する
変数:Texturesの配列分、毎フレームごとにTextureを変更する
変数名 | 変数の型 |
---|---|
Material | Material Instance Dynamic(リファレンス) |
Textures | Texture2D(リファレンス)の配列 |
Count | Integer |
Texturesのデフォルト値を300枚設定すればいいが、さすがにつらい
AssetからTexture2Dの配列を取得するBlueprintFunctionLibraryを作成する
BlueprintFunctionLibraryの作成方法は以下を参照
http://qiita.com/gansaibow/items/7dee2f3d61af9bd8b37f
// 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();
};
// 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に設定する
実行すると画像の連番が毎フレーム書き換えられる
C++でAssetを取得できる方法が分かったので、配列をEditorで1個1個設定しなくて済む 動画を静止画連番に書き出して、Textureの連番を毎フレーム書き換えて動画を再現するとか簡単に出来る #UE4Study pic.twitter.com/gpnrFVxWhz
— GAN彩坊(光の戦士) (@gansaibow) 2017年3月27日