# Changing UObject, Changing Settings

**URL:** <https://forums.unrealengine.com/t/changing-uobject-changing-settings/2033811>\
**Category:** C++\
**Tags:** unreal-engine, editor, CPP, question\
**Created:** [September 23, 2024, 9:14am UTC](https://forums.unrealengine.com/t/changing-uobject-changing-settings/2033811 "2024-09-23T09:14:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RealNyntexx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RealNyntexx](https://forums.unrealengine.com/u/RealNyntexx)\
**Post date:** [September 23, 2024, 9:14am UTC](https://forums.unrealengine.com/t/changing-uobject-changing-settings/2033811/1 "2024-09-23T09:14:55Z")

</div>

I have an ActorComponent called USquadComponent. This SquadComponent has 2 members that I currently care about:

```auto
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Squad")
TSubclassOf<USquadFormation> FormationClass = nullptr;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Squad", meta = (ShowInnerProperties))
USquadFormation* SquadFormation = nullptr;

```

Now, when I’m in the editor and change my formation class I want the subobject SquadFormation to be changed to that new class and edit it’s values.  
For example, I have a Circle Formation that has 2 additional members that are not in the parent class.

The problem is that just cannot find a way that either doesn’t crash the engine on startup or doesn’t let me save the Actor containing this component.  
I looked a little bit through the source code and stumbled upon the UObject::Modify function and started to make use of it:

```auto
#if WITH_EDITOR
bool USquadComponent::Modify(bool bAlwaysMarkDirty)
{
    if(GEngine->IsEditor())
    {
	    GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, 
		"SquadComponent Modify");

        if(FormationClass != nullptr)
        {
	        //this is crashing
	        if(!SquadFormation->IsA(FormationClass) && FormationClass->IsValidLowLevel())
	        {
	        }
        }
	return Super::Modify(bAlwaysMarkDirty);
}
#endif

```

Little side note, since I am using methods in the SquadFormation class I cannot use a struct because I want to make the SquadFormation to also be available to override in blueprints.

I think I am just missing some small things here since when I’m creating the SquadFormation in the constructor I am able to change the settings to my liking, I just don’t know how to make the class editable.

---

<div class="post-metadata">

**Author:** ![KaidoomDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaidoomdev/32/977996_2.png) [@KaidoomDev](https://forums.unrealengine.com/u/KaidoomDev)\
**Post date:** [September 23, 2024, 4:49pm UTC](https://forums.unrealengine.com/t/changing-uobject-changing-settings/2033811/2 "2024-09-23T16:49:48Z")

</div>

Could it be that you’re not checking if **SquadFormation** is null before executing the IsA function.

---

<div class="post-metadata">

**Author:** ![RealNyntexx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RealNyntexx](https://forums.unrealengine.com/u/RealNyntexx)\
**Post date:** [September 23, 2024, 5:26pm UTC](https://forums.unrealengine.com/t/changing-uobject-changing-settings/2033811/3 "2024-09-23T17:26:47Z")

</div>

my god… yea, it’s just me not realising a simple error xD

Also:

```auto
SquadFormation = Cast<USquadFormation>(CreateDefaultSubobject(
FormationClass->GetFName(), FormationClass, FormationClass, true, false));

```

crashes the editor so I have to use

```auto
SquadFormation = NewObject<USquadFormation>(this, FormationClass.Get(), FormationClass->GetFName());

```

Maybe someone can give some more context on why I have to use one rather than the other.  
Anyway, at least I knew it was something small, thank you.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [October 23, 2024, 5:27pm UTC](https://forums.unrealengine.com/t/changing-uobject-changing-settings/2033811/4 "2024-10-23T17:27:38Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
