Sometimes when we create a scene, a particular actor we want to give it a specific icon for easy observation. such as this:
It is also very simple to implement, and you need to write C + + code:
We create an actor called Amyactor, which contains a sprite (sprite), which is responsible for displaying the custom icon: the code is as follows
#pragma once#include "gameframework/actor.h" #include "components/billboardcomponent.h" #include " Myactor.generated.h "/** * */uclass () class Nantopdown_api amyactor:public aactor{generated_uclass_body ()// virtual void Beginplay () OVERRIDE; Uproperty () tsubobjectptr<ubillboardcomponent> spritecomponent; Utexture2d* spritetexture;};
#include "NanTopDown.h" #include "MyActor.h" Amyactor::amyactor (const class fpostconstructinitializeproperties& PCIP): Super (PCIP) {struct fconstructorstatics{constructorhelpers::fobjectfinderoptional<utexture2d> Notetextureobject; FName id_notes; Ftext name_notes; Fconstructorstatics (): Notetextureobject (Text ("Texture2d '/game/textures/myicon.myicon ')"), Id_notes (Text ("Notes" ), Name_notes (Nsloctext ("Spritecategory", "Notes", "Notes")) {}};static fconstructorstatics Cs; Tsubobjectptr<uscenecomponent> scenecomponent = Pcip. Createdefaultsubobject<uscenecomponent> (This, TEXT ("Scenecomp")); Rootcomponent = scenecomponent; rootcomponent->mobility = ecomponentmobility::static; #if with_editoronly_dataspritecomponent = PCIP. Createeditoronlydefaultsubobject<ubillboardcomponent> (This, TEXT ("Sprite")); if (spritecomponent) { Spritecomponent->sprite = Cs.NoteTextureObject.Get (); Spritecomponent->spriteinfo.category = cs.id_notes; Spritecomponent->spriteinfo.displayname = CS.name_notes; Spritecomponent->attachparent = rootcomponent; spritecomponent->mobility = ecomponentmobility::static;} #endif}
Amyactor has only one ubillboardcomponent component, you can see the custom picture by adding a scene.
Reference article: Https://wiki.unrealengine.com/Add_in_editor_Icon_to_your_Custom_Actor
Unreal Engine 4 C + + creates custom icons for actors in the editor