Code Monkey home page Code Monkey logo

Comments (12)

tranek avatar tranek commented on July 20, 2024

In the project input settings I have an input action for Jump.

In GASDocumentation.h there's a struct of all the input bindings that are bound to the ASC:

UENUM(BlueprintType)
enum class EGDAbilityInputID : uint8
{
	// 0 None
	None			UMETA(DisplayName = "None"),
	// 1 Confirm
	Confirm			UMETA(DisplayName = "Confirm"),
	// 2 Cancel
	Cancel			UMETA(DisplayName = "Cancel"),
	// 3 LMB
	Ability1		UMETA(DisplayName = "Ability1"),
	// 4 RMB
	Ability2		UMETA(DisplayName = "Ability2"),
	// 5 Q
	Ability3		UMETA(DisplayName = "Ability3"),
	// 6 E
	Ability4		UMETA(DisplayName = "Ability4"),
	// 7 R
	Ability5		UMETA(DisplayName = "Ability5"),
	// 8 Sprint
	Sprint			UMETA(DisplayName = "Sprint"),
	// 9 Jump
	Jump			UMETA(DisplayName = "Jump")
};

GDHeroCharacter binds the InputComponent to the ASC using that struct as a mapping.

void AGDHeroCharacter::BindASCInput()
{
	if (!ASCInputBound && AbilitySystemComponent.IsValid() && IsValid(InputComponent))
	{
		AbilitySystemComponent->BindAbilityActivationToInputComponent(InputComponent, FGameplayAbilityInputBinds(FString("ConfirmTarget"),
			FString("CancelTarget"), FString("EGDAbilityInputID"), static_cast<int32>(EGDAbilityInputID::Confirm), static_cast<int32>(EGDAbilityInputID::Cancel)));

		ASCInputBound = true;
	}
}

A EGDAbilityInputID is stored on the UGDGameplayAbility class (set manually in the blueprint or C++ constructor of the ability subclass) that I read from when I grant the ability to the ASC that tells it to associate that ability with that input action.

void AGDCharacterBase::AddCharacterAbilities()
{
	// Grant abilities, but only on the server	
	if (GetLocalRole() != ROLE_Authority || !AbilitySystemComponent.IsValid() || AbilitySystemComponent->CharacterAbilitiesGiven)
	{
		return;
	}

	for (TSubclassOf<UGDGameplayAbility>& StartupAbility : CharacterAbilities)
	{
		AbilitySystemComponent->GiveAbility(
			FGameplayAbilitySpec(StartupAbility, GetAbilityLevel(StartupAbility.GetDefaultObject()->AbilityID), static_cast<int32>(StartupAbility.GetDefaultObject()->AbilityInputID), this));
	}

	AbilitySystemComponent->CharacterAbilitiesGiven = true;
}

Jump's input action EGDAbilityInputID is set in the ability constructor.

UGDGA_CharacterJump::UGDGA_CharacterJump()
{
	AbilityInputID = EGDAbilityInputID::Jump;
	InstancingPolicy = EGameplayAbilityInstancingPolicy::NonInstanced;
	AbilityTags.AddTag(FGameplayTag::RequestGameplayTag(FName("Ability.Jump")));

}

Any abilities bound to an input like this are automatically activated when the input is triggered. This also allows the ability to use the input related ability tasks.

from gasdocumentation.

ANURAGX avatar ANURAGX commented on July 20, 2024

I will check it.

from gasdocumentation.

ANURAGX avatar ANURAGX commented on July 20, 2024

One more question

Why are you doing this at 2 places. One inside Character and another inside Player Controller.

to be precise
Character -> PossessedBy
Controller -> OnPossess

	if (PS)
	{
		// Set the ASC on the Server. Clients do this in OnRep_PlayerState()
		AbilitySystemComponent = Cast<UGDAbilitySystemComponent>(PS->GetAbilitySystemComponent());

		// AI won't have PlayerControllers so we can init again here just to be sure. No harm in initing twice for heroes that have PlayerControllers.
		PS->GetAbilitySystemComponent()->InitAbilityActorInfo(PS, this);

		

from gasdocumentation.

tranek avatar tranek commented on July 20, 2024

The InitAbilityActorInfo()? It might be redundant and that's okay. I think I made the PlayerController version first thinking that I would catch all new pawns but then realized when making the GDHeroCharacter that the AI don't have PlayerControllers so they needed to init the ASC either in AIController or in the GDHeroCharacter.

I would expect if you just have the one in GDHeroCharacter that you'll be fine and cover every scenario.

from gasdocumentation.

tranek avatar tranek commented on July 20, 2024

I'll add that it also guarantees that the player's ASC (on the PlayerState) always has a valid AvatarActor. I'm not sure if that matters or not.

from gasdocumentation.

ANURAGX avatar ANURAGX commented on July 20, 2024
enum class EGDAbilityInputID : uint8
{
	// 0 None
	None			UMETA(DisplayName = "None"),
	// 1 Confirm
	Confirm			UMETA(DisplayName = "Confirm"),
	// 2 Cancel
	Cancel			UMETA(DisplayName = "Cancel"),
	// 3 LMB
	Ability1		UMETA(DisplayName = "Ability1"),
	// 4 RMB
	Ability2		UMETA(DisplayName = "Ability2"),
	// 5 Q
	Ability3		UMETA(DisplayName = "Ability3"),
	// 6 E
	Ability4		UMETA(DisplayName = "Ability4"),
	// 7 R
	Ability5		UMETA(DisplayName = "Ability5"),
	// 8 Sprint
	Sprint			UMETA(DisplayName = "Sprint"),
	// 9 Jump
	Jump			UMETA(DisplayName = "Jump")
};


Does this need to be exact same as that of Binding from editor. ProjectSettings->Inputs
![Untitled](https://user-images.githubusercontent.com/5199691/71480594-efc53f00-281f-11ea-8f00-f002b9b6057e.png)

from gasdocumentation.

ANURAGX avatar ANURAGX commented on July 20, 2024

Will it handle the touch inputs as well.
Why I m asking this because in UE4.24 there is a bug for Android deployment on Android 10. I have reported this bug, but they are not listening.
I couldn't test this.

from gasdocumentation.

tranek avatar tranek commented on July 20, 2024

Yes, the struct members need to be the exact same except for Confirm/Cancel. Please read the README which explains this in more detail. https://github.com/tranek/GASDocumentation#concepts-ga-input

I am not sure about touch inputs, you'll have to check the source code.

from gasdocumentation.

ANURAGX avatar ANURAGX commented on July 20, 2024

What will happen if i m handling input actions as usual along with Gameplay bindings?

from gasdocumentation.

tranek avatar tranek commented on July 20, 2024

It'll be fine. If you handle input actions that are also handled by the ASC, make sure that you don't consume the input otherwise they won't reach the ASC.

from gasdocumentation.

ANURAGX avatar ANURAGX commented on July 20, 2024

Finally I wrote my own JumpingAbility and its working really great. All Thanks to you.
I had setup my input in PlayerController rather than Character what u did.

from gasdocumentation.

ANURAGX avatar ANURAGX commented on July 20, 2024

Adding touch 1 along with spacebar in the input for Jump makes it jump on mobile devices.

from gasdocumentation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.