GameplayAbility TargetData

Hey Guys,

I am having a bit of trouble using gameplay effects inside of abilities. I have screenshots posted below but the problem I am having is that when a character applies a GameplayEffect to another character, I can’t seem to apply the damage attribute from the character using the ability to the other character that I want to apply the effect on. What happens is that it will use the attribute from the character that is receiving the effect.

I believe the problem has something to do with not using the TargetData and passing in my own data structure when activating the ability in order to get the appropriate target. I would use the TargetData but I have no idea how the WaitTargetData task works. I have been playing around with it but can’t see to get it to give me information.

The only information I could find (which actually told me about the WaitTargetData task) was here GameplayAbilities questions - C++ - Unreal Engine Forums.

Update - I did some debugging and it’s failing at line 1388 of GameplayAbility.cpp which reads “FScopedGameplayCueSendContext GameplayCueSendContext;”. It seems like it can’t get the GameplayCueManager but I have it setup. I was able to use a print to verify that the TargetData from actor did contain my target actor.

Update 2 - Ok, I think I actually fixed it. It seems that it requires a GameplayCueManager to be specified or else it will crash. I had specified it but I did it in DefaultEngine.ini instead of DefaultGame.ini. The post below explains it.

I can use the target data from actor just fine now but when I try to use WaitTargetData it crashes because the actor info doesn’t contain the player controller and I’m not sure why.

Also, what would be the best way to use that to do a two stage input on an ability? For instance, activating an ability and then selecting a target with the cursor.

-edit-
I managed to set it up so that I can use confirm/cancel but I am not sure what the best approach is to get the mouse hit result in the ability.

So I ended up using something like below to get target data for my abilities. It would be nice to know how to use the ability system targeting though. I know it’s still in development but it’s fun to play with.



FMyAbililtyTriggerEvent AMyPlayerController::CreateTriggerData()
{
	FHitResult hit;
	FMyAbililtyTriggerEvent triggerEvent;

	GetHitResultUnderCursor(ECollisionChannel::ECC_Camera, false, hit);
	triggerEvent.TargetPosition = hit.Location;
	triggerEvent.TargetActor = hit.Actor.Get();

	return triggerEvent;
}
void AMyPlayerController::AbilityInputPressed(EMyGameplayAbilityInputBinds::Type InputID)
{
	FMyAbililtyTriggerEvent triggerEvent = CreateTriggerData();
	UMyAbilityComponent* EntityComponent = Cast<AMyCharacter>(GetPawn())->EntityComponent;

	triggerEvent.InputID = InputID;

	EntityComponent->SetTriggerEventData(triggerEvent);
	ServerTriggerAbility(triggerEvent);
}

void AMyPlayerController::ServerTriggerAbility_Implementation(FMyAbililtyTriggerEvent TriggerEvent)
{
	AMyCharacter = character = Cast<AMyCharacter>(GetCharacter());
	
	if (character) 
	{
		FGameplayAbilitySpec* abilityToActivate = character->EntityComponent->FindAbilitySpecFromInputID(TriggerEvent.InputID);

		character->EntityComponent->SetTriggerEventData(TriggerEvent);
		character->EntityComponent->TryActivateAbility(abilityToActivate->Handle);
	}
	
}