Home
  • English
  • 中文
Home
  • English
  • 中文
  • Get Started

    • Install
    • Hello LGUI
    • Custom Button
    • Use custom font
    • Prefab workflow
    • Interaction
    • Button from scratch
  • Sample Projects

    • Sample Projects
  • Prefab Workflow

    • LGUI Prefab
    • PrefabEditor
    • LGUILifeCycleBehaviour
    • LGUIPrefabInterface
  • Rendering

    • LGUICanvas
    • Screen Space Overlay
    • World Space - UE Renderer
    • World Space - LGUI Renderer
    • LGUI render flow
    • UICanvasGroup
  • Visual Components

    • UIText
    • UIEffect
    • TextAnimation
    • UIBackgroundBlur
    • UIBackgroundPixelate
  • Events

    • LGUIEventDelegate
    • LGUIEventSystem
  • Interaction Components

    • UISelectable component
  • Layout

    • Basic Layout
    • Auto Layout
  • Tween Animation

    • LTween
    • Use LTween for UI element
  • Performance

    • LGUI Stat
  • ReleaseNotes

    • LGUI 3.x
    • LGUI 2.x
  • FAQ

    • Why use prefab?
    • Update project from LGUI2 to LGUI3
    • Project 3d world position to LGUI's screen 2d position
    • Deproject LGUI's screen position to world
    • Use custom material for UI elements
    • Disable interaction component
    • Find Child by DisplayName
    • Get actor or component inside prefab
    • Anti-aliasing

Prefab workflow

In this section, we will learn how to use LGUIPrefab to reuse our UI content. Basically LGUIPreafb is just a nested hierarchical actor serialization tool, it is not limited to UI create, actually you can use it with any actor.

Prepare a LGUI ScreenSpaceUI.

Follow the HelloWorld section to create a base ScreenSpaceUI.

Create a button as prefab source.

Select "ScreenSpaceUIRoot" actor, right click on the down arrow button, and choose "Create UI Element"->"Button":
step1

Rename the button actor to "MyPrefabButton", set "PosZ" to -100, "Color" to green:
step2

Create prefab.

Select "MyPrefabButton" actor, right click on the down arrow button, and choose "Create Prefab":
step3

Now a save file window will showup:
step4

Click "Save" button, then a prefab asset will appear in "Content" folder:
step5

And notice the "MyPrefabButton" actor in the "Outliner", the down arrow button icon become a prefab icon, and a LGUIPrefabManagerActor appear in "--LGUIPrefabActor--" folder:
step6

Select "MyPrefabButton" actor, right click on the prefab icon and choose "Destroy Actors", so the "MyPrefabButton" actor and it's children are all destroyed:
step7

Reuse prefab in editor.

Select "ScreenSpaceUIRoot" actor, drag "MyPrefabButton_Prefab" asset and drop to anywhre on viewport:
step9

See a "MyPrefabButton" actor is created in viewport and outliner:
step10

Select "Info" actor, drag "MyPrefabButton_Prefab" asset and drop to anywhre on viewport, then a new "MyPrefabButton" will be created (you may need to move it off to see in viewport):
step11

Notice different prefab have different color on prefab icon:
step12

Select both "MyPrefabButton" actor by hold "Ctrl" key and click it, then choose "LGUI Editor Tools"->"Destroy Actors" to destroy both actors and all it's children:
step13

Reuse prefab in runtime.

Right click in empty area of "Content" and choose "Blueprints"->"BlueprintClass":
step15

Select "Actor Component":
step16

Name the created ActorComponent class to "PrefabLoader":
step17

Double click "PrefabLoader" to open blueprint editor:
step18

Drag out "Event Begin Play" and add a "Load Prefab" node:
step19

Drag "MyPrefabButton_Prefab" to "In Prefab" of "Load Prefab" node:
step20

Connect "Get Owner" and "Root Component" node to "In Parent" of "Load Prefab" node:
step21

Click "Compile" and then close the blueprint editor:
step22

Select "ScreenSpaceUIRoot" actor in "Outliner", and drag "PrefabLoader" to it's component stack:
step23

Hit play, you can see a prefab button is created:
step24

Notice the button's color become white, because it is override by UIButton component, now let's modify the prefab to fix it.

Modify prefab.

Exit play mode by click stop button. Double click on the "MyPrefabButton_Prefab" to open PrefabEditor:
step25

Select "MyPrefabButton" actor, select "UIButton" component. UIButton use "ColorTint" on "Transition" property, it will override the TransitionActor's color with "Normal Color":
step26

Change the "Normal Color" to red, see the button in viewport become red too:
step27

Click the "Apply" button in the left top menu of PrefabEditor, so that the changes will apply to prefab asset:
step28

Now close PrefabEditor and hit play, see the loaded button have a red color:
step30

Last Updated:
Contributors: lf2007hf
Prev
Use custom font
Next
Interaction