Weird behavior when accessing other class' data

McBlyadCykovich
Fri, 01 Aug 2025 11:59:47 +0000
Programming & Scripting

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:

UPROPERTY()
   UBehavior* Behavior;

I initialize it in BeginPlay() by:

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:

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

4 posts - 2 participants