How to add const function?


#1

Like this:
void Func() const;


#2

There is no const modifier or equivalent.

Is there anything in particular that you are trying to accomplish?

Since SkookumScript is used for high-level scripting, it is more streamlined to ensure that scripters do not get lost in the details.

It is possible that the language could be extended to have some sort of constant construct in the future, though there are no plans to do so at the moment.


#3

Some functions like ClaculateBaseMagnitude in UGameplayModMagnitudeCalculation is const.

When i create a method, then used after the CalculateBaseMagnitude in Bluprint and receive it’s parameters, compile error occurred.

I had to created in c++ instead of this.

Thanks.


#4

If any of our generated code including generated binding code gave errors then that might be something that needs to be fixed.

Could you please give us some example code and Blueprints that seem to be giving you trouble? Then we can see if we can fix things on our end so you don’t need to write special C++.

I’m glad you were able to get around the problem yourself though. :madsci:


#5

Of course. Here’s my experience:

  1. Create a blueprint BP_DamageMMC inherit from UGameplayModMagnitudeCalculation. I’ll use it to evaluate the attack damage of character.

  2. Create a blueprint BP_Effect_Damage inherit from UGameplayEffect, then add a Damage Modifier, set the MagnitudeCalculationType to CustomCalculationClass, use just created BP_DamageMMC as CalculationClass.

  3. I tried to override ClaculateBaseMagnitude of BP_DamageMMC in SkookumScript, left the blueprint set not override, but it won’t invoke in testing, not when i overrode the blueprint side either. Maybe i misunderstand the override in SkookumScript. So i tried another way then.

  4. Create a method in BP_DamageMMC from SkookumScript side, called calculate_damage, has the same parameter with ClaculateBaseMagnitude, one const UGameplayEffectSpec& Spec, which does the real evaluate things. Then i overrode the ClaculateBaseMagnitude in blueprint, it invoke the calculate_damage, pass the Spec to it. When compiling the blueprint, error came out. Since ClaculateBaseMagnitude is const function, but calculate_damage is not. That’s the reason i posted this question. Then i found another way.

  5. If i create calculate_damage a static method, it will compile. but this cause the game crash. So if the method take the Spec parameter, either compile error or game crash occurs.

That’s all. (for test case, i used SkookumScript to let character’s AbilitySystemComponent apply GameplayEffect to itself directly by BP_ApplyGameplayEffectSpecToSelf.)

At last i wonder how to actually override the c++/blueprint function in SkookumScript, and will they be invoked after override if there are some code invoke them from parent class pointer in source code of engine?

Thanks.


#6

Hey sorry for the late reply: So first of all, SkookumScript currently does not currently support the overriding of BlueprintImplementable event functions. So what you did is the correct workaround.

To address the issues you were experiencing using your workaround, we pushed a fix to GitHub that should allow you to call SkookumScript functions from const Blueprint functions, and it also fixes the crash you were experiencing using the static method. Let us know how it goes!