# BeginPlay() for UObject

**URL:** <https://forums.unrealengine.com/t/beginplay-for-uobject/2454223>\
**Category:** C++\
**Tags:** unreal-engine, CPP, question\
**Created:** [April 13, 2025, 10:59am UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223 "2025-04-13T10:59:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrm\_dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mrm\_dev](https://forums.unrealengine.com/u/mrm_dev)\
**Post date:** [April 13, 2025, 10:59am UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/1 "2025-04-13T10:59:52Z")

</div>

I have a custom object which needs to be automatically initialised _before_ it’s owning Actor invokes `BeginPlay()`, Here’s what I’ve tried so far based on [this](https://forums.unrealengine.com/t/uobject-begin-play-equivalent/472891) question:

MyActor:

```cpp
AMyActor::AMyActor() {
    MyObj = CreateDefaultSubobject<UMyObject>(TEXT("MyObj"));
}

void AMyActor::BeginPlay() {
    Super::BeginPlay();

    if (MyObj) {
        MyObj->DoSomething();
    } 

```

MyObject:

```cpp
void UMyObject::DoSomething() {
    if (ActorOwner) {
      // ... Do something with ActorOwner
    }
}

void UMyObject::PostLoad() {
    Super::PostLoad();

    if (GIsEditor && !GIsPlayInEditorWorld) {
        return;
    }

    Init(GetOuter()); // ActorOwner = Cast<AActor>(GetOuter());
}

```

My main goal here is to avoid having to use `MyObj->Init(this)` inside the `MyActor` and instead the let object initialise itself since it becomes tedious when there are several custom objects

Am I doing this right or is there a better way?

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [April 13, 2025, 2:43pm UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/2 "2025-04-13T14:43:34Z")

</div>

> [@mrm\_dev](#):
>
> My main goal here is to avoid having to use `MyObj->Init(this)`

No, there’s no particularly good hook for this with UObjects. Init functions are the most common practice.

One alternative would be for your object to be a UActorComponent instead of UObject. Those do include additional hooks into the Actor lifetime so that you could do things prior to BeginPlay.

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [April 14, 2025, 3:28am UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/3 "2025-04-14T03:28:17Z")

</div>

you can use  
`virtual void PostInitProperties() override;`

but its not a great solution

---

<div class="post-metadata">

**Author:** ![mrm\_dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mrm\_dev](https://forums.unrealengine.com/u/mrm_dev)\
**Post date:** [April 14, 2025, 5:07am UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/4 "2025-04-14T05:07:49Z")

</div>

I tried that but it doesn’t work as intended

When I store the `GetOuter()` in `PostInitProperties()` and then use it in `DoSomething()` it shows as null value for some reason

```cpp
void UMyObject::PostInitProperties() {
    Super::PostInitProperties();

    if (GIsEditor && !GIsPlayInEditorWorld) {
        return;
    }

    Init(GetOuter()); // ActorOwner = Cast<AActor>(GetOuter());
}

void UMyObject::DoSomething() {
    ActorOwner // This is null/invalid for some reason
}
```

---

<div class="post-metadata">

**Author:** ![mrm\_dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mrm\_dev](https://forums.unrealengine.com/u/mrm_dev)\
**Post date:** [April 14, 2025, 5:09am UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/5 "2025-04-14T05:09:46Z")

</div>

I have several UObjects and I don’t think it would make sense for them to be `UActorComponent`

Is there really no other way?

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [April 14, 2025, 5:23am UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/6 "2025-04-14T05:23:35Z")

</div>

whats the problem with all the custom objects having a parent class with an overridable Init()?

---

<div class="post-metadata">

**Author:** ![mrm\_dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mrm\_dev](https://forums.unrealengine.com/u/mrm_dev)\
**Post date:** [April 14, 2025, 2:45pm UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/7 "2025-04-14T14:45:49Z")

</div>

There’s no problem with it  
The problem is the need to repeatedly call Init() instead of it being taken care of internally

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [April 14, 2025, 2:49pm UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/8 "2025-04-14T14:49:18Z")

</div>

just wrap it in a static

---

<div class="post-metadata">

**Author:** ![mrm\_dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mrm\_dev](https://forums.unrealengine.com/u/mrm_dev)\
**Post date:** [April 15, 2025, 4:30am UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/9 "2025-04-15T04:30:33Z")

</div>

I don’t follow what do you mean by wrapping it in static?

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [April 15, 2025, 5:00am UTC](https://forums.unrealengine.com/t/beginplay-for-uobject/2454223/10 "2025-04-15T05:00:53Z")

</div>

i mean create a static function that creates and initializes your Object,
