# Weird behavior when accessing other class' data

**URL:** <https://forums.unrealengine.com/t/weird-behavior-when-accessing-other-class-data/2626313>\
**Category:** Programming & Scripting\
**Tags:** reference, unreal-engine, pointer, CPP\
**Created:** [August 1, 2025, 11:59am UTC](https://forums.unrealengine.com/t/weird-behavior-when-accessing-other-class-data/2626313 "2025-08-01T11:59:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![McBlyadCykovich](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@McBlyadCykovich](https://forums.unrealengine.com/u/McBlyadCykovich)\
**Post date:** [August 1, 2025, 11:59am UTC](https://forums.unrealengine.com/t/weird-behavior-when-accessing-other-class-data/2626313/1 "2025-08-01T11:59:47Z")

</div>

I am not sure if anyone has experience the same problem but I hope someone did because it drives me crazy.

I have ASimpleCharacter which holds:

```auto
UPROPERTY()
   UBehavior* Behavior;

```

I initialize it in BeginPlay() by:

```auto
Behavior = NewObject<UBehavior>(this, BehaviorClass);

```

Then while playing, in the SimpleCharacters’s Tick() when I access UBehavior data, it doesn’t give the proper values that Behavior holds, it gives others. When I try changing value of let’s say the Behavior’s A variable (Behavior-\>A = 0.f, it makes it 0.f but I get this value only from within ASimpleCharacter, within Behavior it stays the same 1000.f as it was). It’s like the references are wrong. But they’re not, I’ve done all sorts of checks. It’s the same pointer, the same address all the time. I checked the references on both objects from both objects, I checked all the objects of their classes globally (in my case they are single instances), I checked CODs. There is no way I duplicate object or something.

But when I do something like that:

```auto
this->SimpleCharacter->Behavior 

```

It gives proper values which would only make me think that the SimpleCharacter has a bad reference, and it points to another UBehavior, but there is no indications of it.

Please, help. I am about to lose it

---

<div class="post-metadata">

**Author:** ![Chatouille](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chatouille/32/1194622_2.png) [@Chatouille](https://forums.unrealengine.com/u/Chatouille)\
**Post date:** [August 1, 2025, 1:01pm UTC](https://forums.unrealengine.com/t/weird-behavior-when-accessing-other-class-data/2626313/2 "2025-08-01T13:01:53Z")

</div>

> [@McBlyadCykovich](#):
>
> within Behavior it stays the same 1000.f as it was

What does “within Behavior” mean ?  
Where exactly are you reading 1000.f instead of 0.f ?

Are you trying in multiplayer ?

So far I understand that you’re creating the object from ASimpleCharacter’s BeginPlay, and reading/updating it from ASimpleCharacter’s Tick, and that part works.  
What is the part that doesn’t ? Send more details.

---

<div class="post-metadata">

**Author:** ![McBlyadCykovich](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@McBlyadCykovich](https://forums.unrealengine.com/u/McBlyadCykovich)\
**Post date:** [August 1, 2025, 1:48pm UTC](https://forums.unrealengine.com/t/weird-behavior-when-accessing-other-class-data/2626313/3 "2025-08-01T13:48:13Z")

</div>

@Chatouille

Apologies if it unclear. Let’s say I use `ASimpleCharacter::Tick()` and `UBehavior::ProcessBehavior()`.

I want to change and log `UBehavior::VariableA` from `ASimpleCharacter::Tick`;

Inside of `ASimpleCharacter` I have a reference to `UBehavior`, let’s just call it `Behavior` which I get here:

```auto
void ASimpleCharacter::BeginPlay()
{
	Super::BeginPlay();

    {
         * code *
    }

    {
         Behavior = NewObject<UBehavior>(this, BehaviorClass_);
    }

    {
         * code *
    }
}

```

The value of `Behavior->VariableA` is by default `1000.f`;

`UBehavior::ProcessBehavior()` is:

```auto
UBehavior::ProcessBehavior()
{
   log(VariableA);                             
   VariableA *= 2.f;
   log(VariableA);                               
}

```

Let’s say, I run `ASimpleCharacter::Tick()`:

```auto
ASimpleCharacter::Tick()
{
   log(Behavior->VariableA); // 1.f
   Behavior->VariableA += 10.f;
   log(Behavior->VariableA); // 11.f

   Behavior->ProcessBehavior(); // 1000.f
                                        // 2000.f
}

```

The next iteration it’s going to be:

```auto
ASimpleCharacter::Tick()
{
   log(Behavior->VariableA); // 11.f
   Behavior->VariableA += 10.f;
   log(Behavior->VariableA); // 21.f

   Behavior->ProcessBehavior(); // 2000.f
                                        // 4000.f
}

```

No multiplayer. The game is singleplayer

---

<div class="post-metadata">

**Author:** ![McBlyadCykovich](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@McBlyadCykovich](https://forums.unrealengine.com/u/McBlyadCykovich)\
**Post date:** [August 1, 2025, 4:40pm UTC](https://forums.unrealengine.com/t/weird-behavior-when-accessing-other-class-data/2626313/4 "2025-08-01T16:40:16Z")

</div>

I think I kind of fixed it by messing with includes and gen files, at least for now. It has something to do with unreal reflection system, it’s not the first time I get some stupid bugs that just don’t make sense, and in the end it always turns out that the unreal compiler outputs some ridiculous operations from the code it parsed.
