Editor crash when running Console Command during Play

Sure thing!

After hitting Play, I bring up the console and type in “TestCombat” (without the quotation marks)

This is the console command that should launch the battle but it’s here where it’ll crash.

So the issue is that when you use TestCombat in the console, you are calling functions that are relying on objects existing. Because many of your functions don’t check to see if the pointer is valid (the class has been created), you are getting a access violation.

[GameCharacter.cpp]

void UGameCharacter::BeginMakeDecision()
{
	if( decisionMaker )
	{
		this->decisionMaker->BeginMakeDecision(this);
	}
}

bool UGameCharacter::MakeDecision(float DeltaSeconds)
{
	if( decisionMaker )
	{
		return this->decisionMaker->MakeDecision(DeltaSeconds);
	}
	return false;
}

void UGameCharacter::BeginExecuteAction()
{
	if( combatAction )
	{
		this->combatAction->BeginExecuteAction(this);
	}
}

[RPGGameMode.cpp]

   if( gameInstance && CombatUIInstance )
	{
		for( int i = 0; i < gameInstance->PartyMembers.Num(); i++ )
		{
			CombatUIInstance->AddPlayerCharacterPanel(gameInstance->PartyMembers[ i ]);
			gameInstance->PartyMembers[ i ]->decisionMaker = this->CombatUIInstance;
		}
	}

	if( CombatUIInstance )
	{
		for( int i = 0; i < enemyParty.Num(); i++ )
		{
			CombatUIInstance->AddEnemyCharacterPanel(enemyParty[ i ]);
		}
	}

You should now see the Warning log I wrote earlier: “LogTemp:Warning: CombatUIClass has not been set, check Constructor of MyUserWidget”

Also, as a side note. You do not need to use, “this->MemberVariable”, if you don’t want to. If the variable or function belongs to the class you are calling it from, you can just call it. As an example:

This:

 void UGameCharacter::BeginMakeDecision()
 {
     if( decisionMaker )
     {
         this->decisionMaker->BeginMakeDecision(this);
     }
 }

Can be:

 void UGameCharacter::BeginMakeDecision()
 {
     if( decisionMaker )
     {
         decisionMaker->BeginMakeDecision(this);
     }
 }

Oh perfect! I can’t believe I missed putting a check to see if those objects existed >_< !

At least now that gives me a starting point to figure out why the CombatUIClass isn’t initializing.

On the side note, ahhhh ok that makes sense! Because starting with a this would be almost irrelevant because like you said, it belongs to the class already.

Thank you so much for your help, I really appreciate it! (Seriously, having to go through a beginner’s code base, especially if they’re basically almost replicating a book to understand C++, would be a ■■■■■■■ nightmare haha)
This has really helped me understand scripting in UE a lot more

Not a problem.

When it comes to the book, keep an open mind. I am guessing that given the pace the engine is updated, there will be some portions of it that are out of date.

There is a ton of information on the Answer Hub, Wiki, Forums, and YouTube that will help you fill in some gaps from what the book may miss.

Good luck.

Will do!

I found out that there’s a inheritance issue with the CombatUIWidget class and that’s why the CreateWidget function isn’t working correctly. It’s throwing that error that says that CreateWidget can only work with UUserWidget children (which CombatUIWidget inherits from).

That’s at least a solid direction I can run with in the morning!

Thanks again!