Code Monkey home page Code Monkey logo

Comments (3)

bohdon avatar bohdon commented on June 21, 2024 4

Excellent was looking for something like this, didn't realize it was a feature that was just hidden by default.

The description in those release notes is really helpful, quoting that here just because it was buried a bit:

New: Introduced the concept of "evaluation channels" to non-instant gameplay effects within the ability system! Evaluation channels enable game-specific control over the order in which modifiers are evaluated in attribute calculations.

A game may specify how many channels it would like to use, as well as what they are named, and then modifiers can specify which channel they work on. The channels are evaluated in order, with the numerical output of the first channel serving as the input to the second channel, and so on.

Example: Imagine a sample attribute with a base value of 100. Now apply a multiplicative mod with magnitude 1.1 in channel 0 and a multiplicative mod with magnitude 1.1 in channel 1. The result will evaluate as ((100 * 1.1) * 1.1) instead of (100 * 1.2).

To use channels in a game, two settings within the INI section for AbilitySystemGlobals must be configured. First, bAllowGameplayModEvaluationChannels must be set to true, and second, the channels that should be used (and their names) must be specified in GameplayModEvaluationChannelAliases. Additionally, a game can optionally specify a default channel to use via DefaultGameplayModEvaluationChannel.

In addition, added various new channel-related functionality to the ability classes' API, such as the ability to base the magnitude of a modifier off of an attribute only evaluated up to a certain channel.

And here's some more important snippets from source after reading into them more:

Each channel gets evaluated in order, with the final result from the previous channel used as the base value for the next channel. This happens in FAggregatorModChannelContainer::EvaluateWithBase:

float FAggregatorModChannelContainer::EvaluateWithBase(float InlineBaseValue, const FAggregatorEvaluateParameters& Parameters) const
{
	float ComputedValue = InlineBaseValue;

	for (auto& ChannelEntry : ModChannelsMap)
	{
		const FAggregatorModChannel& CurChannel = ChannelEntry.Value;
		ComputedValue = CurChannel.EvaluateWithBase(ComputedValue, Parameters);
	}

	return ComputedValue;
}

Note that although it's iterating a map, the order of the map is automatically managed in FAggregatorModChannelContainer::FindOrAddModChannel, to make sure that the channels are always evaluated in order:

FAggregatorModChannel& FAggregatorModChannelContainer::FindOrAddModChannel(EGameplayModEvaluationChannel Channel)
{
	FAggregatorModChannel* FoundChannel = ModChannelsMap.Find(Channel);
	if (!FoundChannel)
	{
		// Adding a new channel, need to resort the map to preserve key order for evaluation
		ModChannelsMap.Add(Channel);
		ModChannelsMap.KeySort(TLess<EGameplayModEvaluationChannel>());
		FoundChannel = ModChannelsMap.Find(Channel);
	}
	check(FoundChannel);
	return *FoundChannel;
}

Here's a practical example in which a character's move speed is being overridden by a Run ability, and then multiplied afterwards to apply a Slow debuff:

  • GE_Run sets the attribute to exactly 650
    gas_mod_channels01

  • GE_Slowed multiplies the attribute by 0.25
    gas_mod_channels02

Since all modifiers in Channel0 are fully evaluated before any modifiers in Channel1, the Override modifier op can be used here while still allowing Add or Multiply operations afterwards by putting them in a higher channel.

One last visual representation of how a subset of the modifier operations within each channel are used for the above example, with 350 as an arbitrary base value:

  • BaseValue = 350
  • Channel0Value = Override (650) OR ((BaseValue + Additive) * Multiplicitive) / Division
  • Channel1Value = Override OR ((Channel0Value + Additive) * Multiplicitive (0.25)) / Division
  • CurrentValue = (650 * 0.25) = 162.5

Thanks again for this great resource 🙏🏼

from gasdocumentation.

tranek avatar tranek commented on June 21, 2024

Hey, thank you.

I've heard of the evaluation channels before but have never used them. I don't want to include them without a working example.

Then you can do Attribute * MyChannel01Mod * MyChannel02Mod.
Or even Attribute * MyChannel01Mod * (MyChannel02Mod1 + MyChannel02Mod2).

Where does that happen?

from gasdocumentation.

namrog84 avatar namrog84 commented on June 21, 2024

This is really useful and great! I was about to start looking into how to modify EvaluateWithBase and really didn't want to dig into engine code to make a simple change. That fixes what I thought was a GAS shortcoming perfectly!

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.