VC++ for Unreal Engine[edit]
Pipeline[edit]
Runtime[edit]
- 空のプロジェクトを C++ で作成
- Visual Studio Integration Tools プラグインを有効化.再起動.
- 空のプラグインを作る
- uplugin ファイル にターゲットを記述 (Win64とか)
"Modules": [
{
"Name": "OARSelectMaterial",
"Type": "Runtime",
"LoadingPhase": "Default",
"WhitelistPlatforms" : [
"Win64",
]
}
- Build.cs ファイルの PrivateDependencyModuleNames に依存モジュール名を追加.
"StaticMeshEditor",
"EditorSubsystem",
"ImportSubsystem",
- 出力ログを表示させて,一度 プラグインをパッケージ化してみる.
- UE のツールから 新規 C++クラス... を選択
- クラスタイプは パブリック,ファイル名の横の ターゲットモジュールで作成したプラグインを選択.パス 注意.
Android[edit]
JDK, NDK[edit]
- JDK: jdk-8u202-windows-x64.exe
- NDK: Android Studio (android-studio-2023.1.1.28-windows.exe) から入れる (25.1.8937393)
MYPROJECT_API[edit]
#define MYPROJECT_API DLLEXPORT
- DLLEXPORT と書き換えるとエラー.DllExport じゃね?
FName _name = ......;
UE_LOG(LogTemp, Log, TEXT("==> %s"), *_name.ToString());
FString[edit]
FString _str = ......;
UE_LOG(LogTemp, Log, TEXT("==> %s"), *_str);
FString TestHUDString = FString(TEXT("This is my test FString."));
- Equals()
- Find()
- Contains()
char* 変換[edit]
FSTring _name = ....;
FString mpath = FString(TEXT("/Game/OBJ/")) + _name;
UE_LOG(LogTemp, Log, TEXT("material = %s"), *mpath);
::remove(TCHAR_TO_ANSI (*mpath));
UE_LOG(LogTemp, Log, TEXT("material = %s"), *(CreatedObject->GetName()));
オブジェクトの中心[edit]
FVector center1 = mesh->GetBounds().GetSphere().Center;
FVector center2 = mesh->GetBoundingBox().GetCenter();
まともにいごきたるもの[edit]
- Subsystem たるもの
- メニューにつけたるボタンプラグインといふべきもの
訳わからん エラー[edit]
C++: 不完全クラス型へのポインターは使用できません[edit]
C++: 何か足りない関連のエラー[edit]
- 親クラスを継承した空クラスを作りまくる.
- システムがその辺の環境を勝手に揃える(何を揃えているのか さっぱりさっぱり)
Plugin の書き出し: Remote compiling requires a server name. Use the editor (Project Settings > IOS) to set up your remote compilation settings.[edit]
- 俺は IOS用のプラグインを作るつもりは毛頭ないんだが.... プロジェクト設定で サーバ名を指定しろとか... 何言ってんの?
- ターゲットはホワイトリスト方式とか,初見殺しか! ~.uplugin に記述する.
- 下の Win64 がターゲットプラットフォーム
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.0",
"FriendlyName": "OARSelectMaterial",
"Description": "",
"Category": "Other",
"CreatedBy": "Fumi.Iseki",
"CreatedByURL": "",
"DocsURL": "",
"MarketplaceURL": "",
"SupportURL": "",
"CanContainContent": true,
"IsBetaVersion": false,
"IsExperimentalVersion": false,
"Installed": false,
"Modules": [
{
"Name": "OARSelectMaterial",
"Type": "Runtime",
"LoadingPhase": "Default",
"WhitelistPlatforms" :
[
"Win64",
]
}
]
}
AActor* act = Cast<AActor>(CreatedObject);
act->SetActorLocation(...);
Subsystem[edit]
#include "Subsystems/EditorAssetSubsystem.h"
#include <Subsystems/AssetEditorSubsystem.h>
#include <Subsystems/ActorEditorContextSubsystem.h>
#include <Toolkits/AssetEditorModeUILayer.h>
#include <TransformMeshesTool.h>
UStaticMeshEditorSubsystem* me = GEditor->GetEditorSubsystem<UStaticMeshEditorSubsystem>();
UEditorActorSubsystem* ea = GEditor->GetEditorSubsystem<UEditorActorSubsystem>();
UActorEditorContextSubsystem* ac = GEditor->GetEditorSubsystem<UActorEditorContextSubsystem>();
UAssetEditorSubsystem* ae = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
UAssetEditorUISubsystem* ui = GEditor->GetEditorSubsystem<UAssetEditorUISubsystem>();
UEditorAssetSubsystem* aa = GEditor->GetEditorSubsystem<UEditorAssetSubsystem>();
Menu Button Plugin[edit]
void FPButtonModule::PluginButtonClicked()
{
TArray<AActor*> actors;
UWorld* World = GEditor->GetEditorWorldContext().World();
UGameplayStatics::GetAllActorsOfClass(World, AActor::StaticClass(), actors);
for (AActor* act : actors) {
FString _class_name = act->GetClass()->GetName();
if (_class_name.Find(TEXT("StaticMeshActor")) == 0) {
AStaticMeshActor* satr = Cast<AStaticMeshActor>(act);
UStaticMeshComponent* cmp = satr->GetStaticMeshComponent();
UStaticMesh* mesh = cmp->GetStaticMesh();
UE_LOG(LogTemp, Log, TEXT("MESH NAME = %s %s"), *mesh->GetName());
FVector vv(1000., 1000., 100000.);
act->SetActorLocation(vv);
}
}
}
Subsystem Test (死屍累々)[edit]
MyEditorSubsystem.cpp[edit]
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyEditorSubsystem.h"
#include "Subsystems/EditorAssetSubsystem.h"
void UMyEditorSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
//static FName ImporterRulesAppliedName = FName(TEXT("importer_rules_applied"));
//static FString TrueString = FString(TEXT("True"));
//SetImportedAssetTagAction = NewObject<UIRActionSetAssetTags>();
//SetImportedAssetTagAction->AssetTags.Add(ImporterRulesAppliedName, TrueString);
//CheckImportedAssetTagAction = NewObject<UIRQueryCheckAssetTag>();
//CheckImportedAssetTagAction->AssetTagKey = ImporterRulesAppliedName;
//CheckImportedAssetTagAction->AssetTagValue = TrueString;
if (GEditor == NULL) return;
UImportSubsystem* ImportSubsystem = GEditor->GetEditorSubsystem<UImportSubsystem>();
if (ImportSubsystem!=NULL)
{
OnAssetPostImportHandle = ImportSubsystem->OnAssetPostImport.AddUObject(this, &UMyEditorSubsystem::OnAssetPostImport);
/*
ImportSubsystem->OnAssetPostImport.AddLambda([this](UFactory* Factory, UObject* CreatedObject)
{
//UE_LOG(LogTemp, Log, TEXT("UMyEditorSubsystem::Deinitialize()"));
//UE_LOG(LogTemp, Log, TEXT("================================================"));
if (Factory != NULL) {
FName _name = Factory->GetFName();
UE_LOG(LogTemp, Log, TEXT("==> %s"), *_name.ToString());
}
else {
//UE_LOG(LogTemp, Log, TEXT("Factory is NULL"))
}
//UMaterialEditorMeshComponent* xxx = (UMaterialEditorMeshComponent*)CreatedObject;
//xxx->Set
UEditorAssetSubsystem* EditorAssetSubsystem = GEditor->GetEditorSubsystem<UEditorAssetSubsystem>();
if (CreatedObject != NULL) {
FString _name = CreatedObject->GetName();
//UE_LOG(LogTemp, Log, TEXT("SSS> %s"), *_name);
if (_name.Find(FString(TEXT("MATERIAL_"))) == 0) {
UE_LOG(LogTemp, Log, TEXT("GGGGGGGGGGGGGGGGGGGGGGGG> %s"), *_name);
//UMaterialInstanceDynamic* material = (UMaterialInstanceDynamic*)CreatedObject;
//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
//CreatedObject = ma
//material->SetVectorParameterValue(FName(TEXT("BaseColor")), FLinearColor(1.0f, 0.0f, 0.0f));
//UMaterialInstance* material = (UMaterialInstance*)CreatedObject;
//*CreatedObject = *material;
//UMaterialInstance* material = (UMaterialInstance*)CreatedObject;
//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("diffuse_color")), TEXT("{R:1.0, G:0.0, B:0.0}"));
//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("base_color")), TEXT("{R:1.0, G:0.0, B:0.0}"));
//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("BaseColor")), TEXT("{R:1.0, G:0.0, B:0.0}"));
//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("DiffuseColor")), TEXT("{R:1.0, G:0.0, B:0.0}"));
//FString _tag;
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "BaseColor");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "Color");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "DiffuseColor");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "base_color");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "diffuse_color");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//CreatedObject->Modify();
//UMaterial* material = (UMaterial*)CreatedObject;
//material->Set
//UMaterialInstanceDynamic* material = Cast<UMaterialInstanceDynamic>(CreatedObject);
//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
//material->SetVectorParameterValue(FName(TEXT("Base Color")), FLinearColor(1.0f, 0.0f, 0.0f));
//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
//material->Modify();
//material->SetVectorParameterValue(FName(TEXT("Base Color")), FLinearColor(1.0f, 0.0f, 0.0f));
//CreatedObject->Modify();
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("diffuse_color")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("Input DiffuseColor")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("Input DiffuseColor (Vector3)")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("base_color")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("BaseColor")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//TMap<FName, FString> _maps = EditorAssetSubsystem->GetMetadataTagValues(material);
//for (auto& aaa : _maps) {
// UE_LOG(LogTemp, Log, TEXT("xxxxxxxxxxxxxxx> %s %s"), *(aaa.Key).ToString(), *aaa.Value);
//}
}
}
//UE_LOG(LogTemp, Log, TEXT("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));
//check(IsValid(CheckImportedAssetTagAction) && IsValid(SetImportedAssetTagAction));
//const bool bIsReimport = CheckImportedAssetTagAction->Test(Factory, CreatedObject);
//UImporterRulesDeveloperSettings* DeveloperSettings = GetMutableDefault<UImporterRulesDeveloperSettings>();
//check(IsValid(DeveloperSettings));
for (auto RulesIt = DeveloperSettings->RegisteredRules.CreateIterator(); RulesIt; ++RulesIt)
{
if (CreatedObject->IsA(RulesIt.Key()))
{
for (const auto Rule : RulesIt.Value().Rules)
{
if (!bIsReimport || Rule->bApplyOnReimport)
{
Rule->Apply(Factory, CreatedObject);
}
}
}
}
}
);*/
}
}
void UMyEditorSubsystem::OnAssetPostImport(UFactory* Factory, UObject* CreatedObject)
{
if (CreatedObject != NULL) {
FString _namexx = CreatedObject->GetName();
UE_LOG(LogTemp, Log, TEXT("AAAAAAAAAAAAAAAAAAAAAAAAA> %s"), *_namexx);
FString _classxx = CreatedObject->GetClass()->GetName(); // Material
UE_LOG(LogTemp, Log, TEXT("class -=========> %s"), *_classxx);
if (_classxx.Equals(FString(TEXT("StaticMesh")))) {
UE_LOG(LogTemp, Log, TEXT("AAAAAAAAAAAAAAAAAAAAAAAAA> %s"), *_namexx);
UE_LOG(LogTemp, Log, TEXT("class -=========> %s"), *_classxx);
UStaticMesh* mesh = Cast<UStaticMesh>(CreatedObject);
//CreatedObject->GetAssetRegistryTags(asset);
//for (auto& aaa : masset) {
//aaa.ToSt
/*
//TArray
TArray<FStaticMaterial> smat = mesh->GetStaticMaterials();
int i = 0;
for (auto& mat : smat) {
//auto* matif = mesh->GetMaterial(i);
//FString mname = matif->GetName();
auto matif = mat.MaterialInterface;
FString mname = matif.GetName();
UE_LOG(LogTemp, Log, TEXT("material -=========> %d: %s"),i, *mname);
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(matif, NULL);
material->SetVectorParameterValue(FName(TEXT("BaseColor")), FLinearColor(0.0f, 0.0f, 1.0f));
mesh->SetMaterial(i, material);
i++;
//delete &mat;
}
//mesh->SetStaticMaterials(smat);
*/
int i = 0;
auto* matif = mesh->GetMaterial(i);
while (matif != NULL)
{
FString mname = matif->GetName();
//auto matif = mat.MaterialInterface;
//FString mname = matif.GetName();
UE_LOG(LogTemp, Log, TEXT("material -=========> %d: %s"), i, *mname);
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(matif, NULL);
material->SetVectorParameterValue(FName(TEXT("DeffuseColor")), FLinearColor(0.0f, 0.0f, 1.0f));
material->SetVectorParameterValue(FName(TEXT("base_color")), FLinearColor(0.0f, 0.0f, 1.0f));
//UStaticMeshSocket
//mesh->AddSocket()
//mesh->SetMaterial(i, material);
i++;
//delete &mat;
matif = mesh->GetMaterial(i);
}
/*
//UMaterialInterface* matif = mesh->GetMaterial(0);
auto* matif = mesh->GetMaterial(0);
FString mname = matif->GetName();
UE_LOG(LogTemp, Log, TEXT("material -=========> %s"), *mname);
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(matif, NULL);
material->SetVectorParameterValue(FName(TEXT("BaseColor")), FLinearColor(1.0f, 0.0f, 0.0f));
//material->SetVectorParameterValue(FName(TEXT("DiffuseColor")), FLinearColor(1.0f, 0.0f, 0.0f));
//material->SetVectorParameterValue(FName(TEXT("Color")), FLinearColor(1.0f, 0.0f, 0.0f));
mesh->SetMaterial(0, material);
*/
}
/*
//UE_LOG(LogTemp, Log, TEXT("SSS> %s"), *_name);
if (_namexx.Find(FString(TEXT("MATERIAL_"))) == 0) {
UE_LOG(LogTemp, Log, TEXT("GGGGGGGGGGGGGGGGGGGGGGGG> %s"), *_namexx);
//UEditorAssetSubsystem* EditorAssetSubsystem = GEditor->GetEditorSubsystem<UEditorAssetSubsystem>();
//UMaterialInstanceDynamic* material = (UMaterialInstanceDynamic*)CreatedObject;
//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
//CreatedObject = ma
//material->SetVectorParameterValue(FName(TEXT("BaseColor")), FLinearColor(1.0f, 0.0f, 0.0f));
//UMaterialInstance* material = (UMaterialInstance*)CreatedObject;
//CreatedObject = *material;
//UMaterialInstance* material = (UMaterialInstance*)CreatedObject;
//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("diffuse_color")), TEXT("{R:1.0, G:0.0, B:0.0}"));
//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("base_color")), TEXT("{R:1.0, G:0.0, B:0.0}"));
//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("BaseColor")), TEXT("{R:1.0, G:0.0, B:0.0}"));
//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("DiffuseColor")), TEXT("{R:1.0, G:0.0, B:0.0}"));
//FString _tag;
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "BaseColor");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "Color");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "DiffuseColor");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "base_color");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "diffuse_color");
//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
//CreatedObject->Modify();
//UMaterial* material = (UMaterial*)CreatedObject;
//material->Set
FString _class = CreatedObject->GetClass()->GetName(); // Material
UE_LOG(LogTemp, Log, TEXT("class -=========> %s"), *_class);
//material->
//FMaterialCompiler* xxxx = new FMaterialCompiler();
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
material->SetVectorParameterValue(FName(TEXT("Base Color")), FLinearColor(1.0f, 0.0f, 0.0f));
//FName _sname = CreatedObject->SourceFileTagName();
FAssetData asset;
//TArray<UObject::FAssetRegistryTag> masset;
CreatedObject->GetAssetRegistryTags(asset);
//for (auto& aaa : masset) {
//aaa.ToSt
//CreatedObject->Ass
//UE_LOG(LogTemp, Log, TEXT("====================> %s"), *(masset.ToString()));
//asset.key
//UE_LOG(LogTemp, Log, TEXT("====================> %s"), *_sname.ToString());
//FAssetData
//CreatedObject->GetMate
//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
//material->Modify();
//material->SetVectorParameterValue(FName(TEXT("Base Color")), FLinearColor(1.0f, 0.0f, 0.0f));
//CreatedObject->Modify();
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("diffuse_color")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("Input DiffuseColor")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("Input DiffuseColor (Vector3)")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("base_color")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("BaseColor")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
//TMap<FName, FString> _maps = EditorAssetSubsystem->GetMetadataTagValues(material);
//for (auto& aaa : _maps) {
// UE_LOG(LogTemp, Log, TEXT("xxxxxxxxxxxxxxx> %s %s"), *(aaa.Key).ToString(), *aaa.Value);
//}
}*/
}
//UE_LOG(LogTemp, Log, TEXT("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));
}
void UMyEditorSubsystem::Deinitialize()
{
if (GEditor!=NULL)
{
UImportSubsystem* ImportSubsystem = GEditor->GetEditorSubsystem<UImportSubsystem>();
if (ImportSubsystem!=NULL)
{
ImportSubsystem->OnAssetPostImport.Remove(OnAssetPostImportHandle);
}
}
Super::Deinitialize();
}
MyEditorSubsystem.h[edit]
<pre>
#pragma once
#include "CoreMinimal.h"
#include "EditorSubsystem.h"
#include "MyEditorSubsystem.generated.h"
/**
*
*/
UCLASS(BlueprintType, CollapseCategories)
class MYPROJECT_API UMyEditorSubsystem : public UEditorSubsystem
{
GENERATED_BODY()
//const TMap<FName, FString> _maps;
public:
// Begin UEditorSubsystem Interface
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override;
// End UEditorSubsystem Interface
FDelegateHandle OnAssetPostImportHandle;
//UPROPERTY(Transient)
void OnAssetPostImport(UFactory* Factory, UObject* CreatedObject);
};