# Uobject begin play() equivalent

**URL:** <https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891>\
**Category:** C++\
**Tags:** beginplay, unreal-engine, CPP, question\
**Created:** [October 14, 2020, 2:38am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891 "2020-10-14T02:38:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![zSSkitzz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zSSkitzz](https://forums.unrealengine.com/u/zSSkitzz)\
**Post date:** [October 14, 2020, 2:38am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/1 "2020-10-14T02:38:40Z")

</div>

I’ve made an uobject and there isn’t a begin play function. I have a function I want to execute when the game has started. Is there a begin play alternative I could implement without game modes or creating an actor to fire the function? Perhaps using the GetWorld() function? Thanks!

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [October 14, 2020, 6:17am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/2 "2020-10-14T06:17:10Z")

</div>

Hi! In fact UObject is the base class for all assets, including those that are not intended to be adding on level, that’s why UObject class doesnt contain any logic for that (BeginPlay, EndPlay and so on). As for you UObject - where and who creates it (Actor, Player Controller, etc)?

---

<div class="post-metadata">

**Author:** ![zSSkitzz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zSSkitzz](https://forums.unrealengine.com/u/zSSkitzz)\
**Post date:** [October 14, 2020, 6:18am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/3 "2020-10-14T06:18:57Z")

</div>

I know, but I mean like an event that is fired when the world or game has started, not when the object is in the world which is impossible, which is also why in the title of my question I said equivalent of begin play(), a function or event that would be handled similarly like begin play. I would probably do the implementation on construct, the binding etc.

---

<div class="post-metadata">

**Author:** ![Andrew\_Bindraw](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/andrew_bindraw/32/1008648_2.png) [@Andrew\_Bindraw](https://forums.unrealengine.com/u/Andrew_Bindraw)\
**Post date:** [October 14, 2020, 6:35am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/4 "2020-10-14T06:35:18Z")

</div>

Try override this methods for UObject:

**virtual void PostInitProperties();**

**virtual void PostLoad();**

Checkers:

**FApp::CanEverRender()**

FApp::IsGame() // #if WITH\_EDITOR

Maybe this get some direction for research.

* * *

EDIT: Also check **FCoreDelegates**

OnBeginFrame

OnSamplingInput

OnInit

OnPostEngineInit

OnFEngineLoopInitComplete

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [October 14, 2020, 6:46am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/5 "2020-10-14T06:46:48Z")

</div>

1. Global Delegates

- FWorldDelegates::OnPostWorldCreation
- FWorldDelegates::OnPostWorldInitialization
- LevelsChangedEvent

1. Global actors

- Game Instance Begin Play
- Game Mode Begin Play
- Or your custom global manager actor if you have

---

<div class="post-metadata">

**Author:** ![Andrew\_Bindraw](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/andrew_bindraw/32/1008648_2.png) [@Andrew\_Bindraw](https://forums.unrealengine.com/u/Andrew_Bindraw)\
**Post date:** [October 14, 2020, 6:59am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/6 "2020-10-14T06:59:10Z")

</div>

Yes. **FWorldDelegates** more right direction.)

---

<div class="post-metadata">

**Author:** ![zSSkitzz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zSSkitzz](https://forums.unrealengine.com/u/zSSkitzz)\
**Post date:** [October 14, 2020, 7:05am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/7 "2020-10-14T07:05:05Z")

</div>

Could you show me a quick example on binding the delegate on post world creation. I’m new to delegates in c++ and it’s a little bit confusing. I don’t need an explanation I just need an example on setting it up. Thanks!

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [October 14, 2020, 8:25am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/8 "2020-10-14T08:25:43Z")

</div>

- Defenition for FWorldDelegates::OnPostWorldCreation

DECLARE\_MULTICAST\_DELEGATE\_OneParam(FWorldEvent, UWorld\* /_World_/);

FWorldDelegates::OnPostWorldCreation.AddUobject(yourObj, &UYourClass::OnPostWorldCreation);

UFUNCTION()  
void OnLevelsChangedEvent(UWorld\* world);

- Defenition for FWorldDelegates::OnPostWorldInitialization

DECLARE\_MULTICAST\_DELEGATE\_TwoParams(FWorldInitializationEvent, UWorld\* /_World_/, const UWorld::InitializationValues /_IVS_/);

FWorldDelegates::OnPostWorldInitialization.AddUobject(yourObj, &UYourClass::OnPostWorldCreation);

UFUNCTION()  
void OnLevelsChangedEvent(UWorld\* world, const UWorld::InitializationValues);

- Defenition for LevelsChangedEvent

DECLARE\_EVENT(UWorld, FOnLevelsChangedEvent);

GetWorld()-\>LevelsChangedEvent.AddUobject(yourObj, &UYourClass::OnLevelsChangedEvent);

UFUNCTION()  
void OnLevelsChangedEvent();

Here is docs: [Delegates | Unreal Engine Documentation](https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Delegates/index.html)

---

<div class="post-metadata">

**Author:** ![zSSkitzz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zSSkitzz](https://forums.unrealengine.com/u/zSSkitzz)\
**Post date:** [October 14, 2020, 7:03pm UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/9 "2020-10-14T19:03:13Z")

</div>

> Defenition for  
> FWorldDelegates::OnPostWorldCreation
> 
> DECLARE\_MULTICAST\_DELEGATE\_OneParam(FWorldEvent,  
> UWorld\* /World/);
> 
> FWorldDelegates::OnPostWorldCreation.AddUobject(yourObj,  
> &UYourClass::OnPostWorldCreation);

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7069a375](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7069a375](https://forums.unrealengine.com/u/anonymous_user_7069a375)\
**Post date:** [October 15, 2020, 5:59am UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/10 "2020-10-15T05:59:01Z")

</div>

The are right. UObject doesn’t know is World exist. When you create your UObject dynamically with NewObject function, you should pass an Outer(basically “Owner”) - some actor in the world.

To make it work out-of-box:

1. Create your own BeginPlay() function

2. Override PostInitProperties() function(called after the C++ constructor) and call your BeginPlay() in it. But you should be carefull, this function is called in editor too, so you should first check, if World exist.

3. Override GetWorld() function in your UObject

Thats all, now you have BeginPlay() for your UObject.  
Have a nice day)

---

<div class="post-metadata">

**Author:** ![6r0m](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/6r0m/32/1194563_2.png) [@6r0m](https://forums.unrealengine.com/u/6r0m)\
**Post date:** [July 12, 2021, 1:51pm UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/11 "2021-07-12T13:51:29Z")

</div>

thanks, in my case GIsPlayInEditorWorld is always false (4.26). I’m using: if (FApp::IsGame()).

---

<div class="post-metadata">

**Author:** ![Socke81](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/socke81/32/1194535_2.png) [@Socke81](https://forums.unrealengine.com/u/Socke81)\
**Post date:** [July 19, 2023, 4:21pm UTC](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891/12 "2023-07-19T16:21:11Z")

</div>

Since it can be somewhat difficult to understand what zSSkitzz has written, here again in simpler terms. Create a function.

> UFUNCTION()  
> void beginPlay(UWorld\* world);

Then in the constructor or somewhere else bind the function to the event.

> FWorldDelegates::OnPostWorldCreation.AddUObject(this, &UMyClass::beginPlay);
