Add in editor Icon to your Custom Actor - Epic Wiki
# Add in editor Icon to your Custom Actor
Rate this Article:
5.00
(one vote)
Approved for Versions:(please verify)
# Contents
# Overview
Greetings!
This is a code snippets show you how to add in editor icon to your custom Actor.
Just like this:
I add some comment for reference.
# MyActor.h
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved. #pragma once #include "GameFramework/Actor.h" #include "MyActor.generated.h" /** * */ UCLASS() class AMyActor : public AActor { GENERATED_UCLASS_BODY() virtual void BeginPlay() OVERRIDE; UPROPERTY() // A UBillboardComponent to hold Icon sprite TSubobjectPtr<UBillboardComponent> SpriteComponent; // Icon sprite UTexture2D* SpriteTexture;; };
# MyActor.cpp
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved. #include "MyActor.h" AMyActor::AMyActor(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { // Structure to hold one-time initialization struct FConstructorStatics { // A helper class object we use to find target UTexture2D object in resource package ConstructorHelpers::FObjectFinderOptional<UTexture2D> NoteTextureObject; // Icon sprite category name FName ID_Notes; // Icon sprite display name FText NAME_Notes; FConstructorStatics() // Use helper class object to find the texture // "/Engine/EditorResources/S_Note" is resource path : NoteTextureObject(TEXT("/Engine/EditorResources/S_Note")) , ID_Notes(TEXT("Notes")) , NAME_Notes(NSLOCTEXT("SpriteCategory", "Notes", "Notes")) { } }; static FConstructorStatics ConstructorStatics; // We need a scene component to attach Icon sprite TSubobjectPtr<USceneComponent> SceneComponent = PCIP.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneComp")); RootComponent = SceneComponent; RootComponent->Mobility = EComponentMobility::Static; #if WITH_EDITORONLY_DATA SpriteComponent = PCIP.CreateEditorOnlyDefaultSubobject<UBillboardComponent>(this, TEXT("Sprite")); if (SpriteComponent) { SpriteComponent->Sprite = ConstructorStatics.NoteTextureObject.Get(); // Get the sprite texture from helper class object SpriteComponent->SpriteInfo.Category = ConstructorStatics.ID_Notes; // Assign sprite category name SpriteComponent->SpriteInfo.DisplayName = ConstructorStatics.NAME_Notes; // Assign sprite display name SpriteComponent->AttachParent = RootComponent; // Attach sprite to scene component SpriteComponent->Mobility = EComponentMobility::Static; } #endif // WITH_EDITORONLY_DATA }
# Conclusion
Please refer to Engine\Source\Runtime\Engine\Private\Note.cpp for more information.
Enjoy!
Retrieved from "https://wiki.unrealengine.com/index.php?title=Add_in_editor_Icon_to_your_Custom_Actor&oldid=8212"
Hidden category: