Crash when spawning Actor with WidgetComponent

I asked a question here and the only way i found to fix that was by putting the object itself on the level first, after that SpawnActor initializations from that type start to work. There is probably some logic that is missing when spawned using SpawnActor.

Hello xlar8or,

I have a few questions for you that will help narrow down the issue that you are experiencing.

Quick questions:

  1. Can you reproduce this in a clean project?
  2. If you can reproduce this in a clean project, could you provide an accurate and detailed set of steps to reproduce the issue?
  3. Are you using the Binary or Source version of the engine?

Yes, i just tried it on a fresh First Person Template and it has the same problem. I’m using the source version from GitHub. To replicate just create a new C++ First Person Template with Starter Content (shouldn’t make any difference) named MyProject. Extract the content of the zip to replace the source code and blueprints, put 1 client with dedicated server and start the game. Basically what i did was create a new ATest class with a skeletal mesh and create a new blueprint that derives from that and add a Widget component. On the character i have a property TestClass that allows me to select the blueprint class. On PostInitializeComponents i spawn a new actor from that class on the server and set that to the TestObject variable, which replicates. The only way i found for it not to crash is to have the blueprint already placed on the level, that way it won’t crash.

Source code and blueprints

Hello xlar8or,

I followed your instructions but I was unable to reproduce this issue on my end. Could you explain to me what it is exactly you are hoping to achieve? After I have a better understanding of your goal(s) I may be able to assist in a workaround or an alternate method. Also, could you tell me what version of the engine it is that you are using?

I was trying to create a Map actor that has a UMG Widget where i can pan, zoom and interact. Since my game is multiplayer i need to replicate that actor, when i do that it crashes. I’m using 4.6.0 git version

Have you tried placing it inside the player controllers? The reason for the crash could be that the widget spawns in before the players and therefore has no player controller. As a test (NOT a solution) could you try placing a delay that lasts long enough for all of your players to spawn before you spawn your widgets? These tests will help narrow down the issue that you are experiencing.

I will try that and i will let know, but do you have any idea why placing an instance in the world fixes the problem?

Hello xlar8or,

I haven’t heard anything back from you in a few days. I wanted to check up and see if you had any new information on this issue.

Sorry for only being able to answer now. I used SetTimer to call a function that spawns the map with a 5 second delay inside the PostInitializeComponents like such:

void AMyCharacter::PostInitializeComponents()
{
	Super::PostInitializeComponents();

	if (Role < ROLE_Authority)
		return;

	GetWorldTimerManager().SetTimer(this, &AMyCharacter::SpawnMap, 5.0f);
}

void AMyCharacter::SpawnMap()
{
	if (MapClass != nullptr)
		Map = Cast<class AMapItem>(GetWorld()->SpawnActor(MapClass));
}

When i run the game after 5 seconds and everything is spawned in the world, it crashes with the same error. I can try to put it on the PlayerCharacter, but i’m not sure if it’s going to make any difference.

Hello xlar8or,

I have recently reported a bug dealing with multiple players and 3D widgets causing a crash. Are you by any chance doing this in split screen?

No, i have split screen turned off, i use different windows for each client :slight_smile:

Hello xlar8or,

Have you tried using blueprints to add a widget component to the characters?

I’m adding the widget component using Blueprints, i didn’t even try to add it using C++.

Hello xlar8or,

I was rereading some of the other comments and I noticed that you said you were using 4.6.0. Have you upgraded since then? I was wondering if you had tried this on 4.6.1? I have also been playing around with your project some more to try and get it to crash. Could you tell me where it is you are adding the instance to the level (the instance needed to keep it from crashing)?

I will try to reproduce it on 4.6.1, i will let you know as soon as i can test that :slight_smile:

Hello xlar8or,

i was just checking in to see if you had gotten a chance to test this in 4.6.1.

Hello xlar8or,

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 offer further assistance.

Thank you.

I apologize for not giving any update regarding this issue. I’ve been really busy working on more important features for my game, so i haven’t been able to look into that, but as soon as i can i will update it :slight_smile:

Hello xlar8or,

Sounds good, feel free to update this post whenever you get any additional information. I will close this for now for tracking purposes. However, please feel free to open in back up at anytime for further assistance.