# "Using incorrect object initializer" when compiling an inherited script

**URL:** <https://forums.unrealengine.com/t/using-incorrect-object-initializer-when-compiling-an-inherited-script/491584>\
**Category:** Blueprint\
**Tags:** inheritance, Class, unreal-engine, crash, CPP, question\
**Created:** [December 3, 2021, 10:31pm UTC](https://forums.unrealengine.com/t/using-incorrect-object-initializer-when-compiling-an-inherited-script/491584 "2021-12-03T22:31:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DissonanceOfMask](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DissonanceOfMask](https://forums.unrealengine.com/u/DissonanceOfMask)\
**Post date:** [December 3, 2021, 10:31pm UTC](https://forums.unrealengine.com/t/using-incorrect-object-initializer-when-compiling-an-inherited-script/491584/1 "2021-12-03T22:31:41Z")

</div>

The situation is i have been trying to compile a class that inherits from a custom pawn class.  
The .h File:

```
#pragma once

#include "CoreMinimal.h"
#include "BasePawn.h"
#include "Tank.generated.h"

/**
 * 
 */
UCLASS()
class TOONTANKS_API ATank : public ABasePawn
{
	GENERATED_BODY()

public:
	ATank();

private:
	UPROPERTY(EditAnywhere)
	class USpringArmComponent* SpringArm;

	UPROPERTY(EditAnywhere)
	float Speed = 200.0f;	
};

```

The .cpp file:

```
#include "Tank.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"

ATank::ATank()
{
	SpringArm->CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring"));
	SpringArm->SetupAttachment(RootComponent);
}

```

The crash report shows:

```
Fatal error: [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/CoreUObject/Private/UObject/Obj.cpp] [Line: 114] Using incorrect object initializer.

UE4Editor_CoreUObject
UE4Editor_ToonTanks!ATank::ATank() [C:\1.) D. GAMEDEV Folder\Unreal Engine Projects\ToonTanksProjectSetup_4.25\ToonTanksProjectSetup_4.25\ToonTanks\Source\ToonTanks\Tank.cpp:11]
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_CoreUObject
UE4Editor_Core
UE4Editor_Core
UE4Editor_Projects
UE4Editor_Projects
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll

```

Im not sure what im doing wrong. im sure my syntax is correct. If anyone posts to assist, i’ll try to respond asap  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![DissonanceOfMask](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DissonanceOfMask](https://forums.unrealengine.com/u/DissonanceOfMask)\
**Post date:** [December 3, 2021, 11:00pm UTC](https://forums.unrealengine.com/t/using-incorrect-object-initializer-when-compiling-an-inherited-script/491584/2 "2021-12-03T23:00:40Z")

</div>

Realized my mistake:  
I was using

`SpringArm->CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring"); `

which should be:

`SpringArm->CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring");`

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a11a5e0e1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a11a5e0e1](https://forums.unrealengine.com/u/anonymous_user_a11a5e0e1)\
**Post date:** [April 30, 2022, 3:52pm UTC](https://forums.unrealengine.com/t/using-incorrect-object-initializer-when-compiling-an-inherited-script/491584/3 "2022-04-30T15:52:05Z")

</div>

I found this and noticed that your solution has a typo, as it’s the same before/after.

For anyone that has this issue, instead of calling a function on the dereferenced springarm, you should be setting it equal to the default subobject:

SpringArm = CreateDefaultSubobject(TEXT(“Spring”);

---

<div class="post-metadata">

**Author:** ![05\_Hercules](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@05\_Hercules](https://forums.unrealengine.com/u/05_Hercules)\
**Post date:** [April 30, 2023, 8:32pm UTC](https://forums.unrealengine.com/t/using-incorrect-object-initializer-when-compiling-an-inherited-script/491584/4 "2023-04-30T20:32:51Z")

</div>

sorry , but whats the difference between two

---

<div class="post-metadata">

**Author:** ![Kaido-77](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kaido-77](https://forums.unrealengine.com/u/Kaido-77)\
**Post date:** [June 24, 2023, 1:22pm UTC](https://forums.unrealengine.com/t/using-incorrect-object-initializer-when-compiling-an-inherited-script/491584/5 "2023-06-24T13:22:53Z")

</div>

thank you, and here i was thinking what i did wrong when initializing the root component lol

---

<div class="post-metadata">

**Author:** ![Anonymous\_3416274c41ab3de19f2474724eec8535](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_3416274c41ab3de19f2474724eec8535](https://forums.unrealengine.com/u/Anonymous_3416274c41ab3de19f2474724eec8535)\
**Post date:** [July 7, 2023, 2:01am UTC](https://forums.unrealengine.com/t/using-incorrect-object-initializer-when-compiling-an-inherited-script/491584/6 "2023-07-07T02:01:12Z")

</div>

> [@DissonanceOfMask](#):
>
> SpringArm-\>CreateDefaultSubobject(TEXT(“Spring”);

SpringArm=CreateDefaultSubobject(TEXT(“Spring”);
