Variable Exposed To Spawn Not Being Set at Begin Play?

(round 2 typing this because internal errors)

I have a variable Tick Rate expose to spawn that isn’t being set when Begin Play is called. I want this to set the tick rate to a desired level right at object creation time.

EDIT:

This is still an issue now on the C++ side. I have a C++ version of my actor component I’m spawning in blueprint, and variables exposed to spawn ARE NOT being set before Begin Play is called. This is resulting in hard crashes because object references are not being set before being accessed.

// BuffComponent.h
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Buff", Meta=(ExposeOnSpawn=true))
FString text = FString(TEXT("Default Text."));

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Buff", Meta=(ExposeOnSpawn=true))
class ATank *owner;

// BuffComponent.cpp
void UBuffComponent::BeginPlay()
{
	Super::BeginPlay();

	//owner->activeBuffs.Add(this);
	GEngine->AddOnScreenDebugMessage(-1, DEBUGTIME, FColor::Yellow, text);

}

For whatever reason, passing through this delay node first allows exposed variable to be set properly even when its set to 0 delay. May not even have to be a delay node, but connecting Begin Play to Set Tick Interval somehow executes first before my Tick Rate is set.

Does your Tick Rate variable have a default value set?

Yeah 0.0. Of course that changes at spawn time depending of the type of buff. This is just the parent class holding the base implementation for all buff classes.

Could it be that it is acting like this because you happen to set your tick rate based on world delta seconds? (which would be 0 at beginplay)

Its not though. I’m setting it in the Spawn node.

I can put a print statement right after Begin Play and it would print the default value of 0, but a print statement after the Delay node and it prints the value set at the Spawn node.

Setting values at the Spawn node is the equivalent of setting values in a class constructor, right? I’m trying figure out why Begin Play is executing before the Spawn constructor finishes.

It does seem very odd…It seems like a bug, but then again its not like you’re trying to do some obscure thing…You’d think this would have been reported sooner…

Anyway it looks like you have a “workaround”
Good luck :slight_smile:

I’d like to hear a dev response to this. I think this is a bug.

There are a few similar questions and some answers on the hub. Having recently run into this behavior I summarized what I found in this response: Expose on spawn doesn't work for custom Components - Programming & Scripting - Unreal Engine Forums

Note the linked answer has a dev-side answer, which essentially says, it is an order-of-operation problem. I suspect solving this issue is not trivial in the backend infrastructure. However as a developer I know that software problem problems can be solved by adding yet another layer of abstraction… which could have drawbacks… performance… complexity. Still it would be nice to get it fixed.