SetActorLabel before gameplay

I’m trying to set the actor label (the label in the scene hierarchy) in my OnConstruction() method, but doing so just crashes the engine. I can do it just fine in PostInitializeComponents(), but that renames it only when the game is being played. Here is the code for that:

void AWorldItem::PostInitializeComponents()


How do I rename my actor from the default actor name, through C++, before the game starts?

Note that the label is for use only in Editor tools, not for shipping games (since ActorLabel is conditionally compiled based on #if WITH_EDITORONLY_DATA).

What are you trying to accomplish with the label? Maybe there is a better solution.

Mostly just for organizational purposes in the scene… I plan on having a bunch of these AWorldItem actors around, and it would be nice to look in the scene and see “Potion”, “Sword”, “Shield”, etc.

I guess I could just use the names of the blueprint class that I place in the world. I’m just confused, why is this function in the engine if it just crashes?

You can always select the Actor in the World Outliner and rename it via the Details panel.

Hmmm… I’ve never tried calling it from OnConstruction, but I could see how SetActorLabel could wreak havoc when renaming an actor. Maybe use PostActorCreated instead of OnConstruction. If this doesn’t work, please post the stack trace of the crash.

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will follow up.