Hi guys! I was wondering something and I can’t seem to find an answer. How would one go about changing the movement speed of a blueprint of my character class within the class of an actor? I’m trying to make a speed power up that whenever you step inside of a sphere, the characters speed is doubled. I have the proximity detection working just I can’t figure out how to access the characters movement speed.
Hello DinosaurDan,
If I’m following you correctly, I believe you’re asking how to change the movement speed of a blueprint of your class that inherits from ACharacter inside of a function that is called in a blueprint of your class that inherits from AActor?
If that’s the case, you’re going to need Casting. Casting is used to take a generic (wildcard) reference and check to see if it is of a certain class. If it is, the cast returns true and returns a specific reference to that class. You can then refer to variables/functions in that class.
To give an example, if you needed to determine what class you’ve hit when an OnHit function has been triggered, or overlapped when an OnBeginOverlap function has triggered, you can use the HitActor parameter to do this:
AMyCharacter* CastedCharacter = Cast<AMyCharacter>(HitActor);
if(CastedCharacter)
{
//Logic using CastedCharacter here
}
If this was the logic you’re using and you hit anything other than a blueprint that inherits from AMyCharacter, the cast would return null so the if would fail. If you do hit a AMyCharacter however, you can then continue as normal and start using CastedCharacter to refer to the HitActor’s specific variables or functions.
hi, you already have an answer from a staff member what should be enough, but just in case someone else have the some question and want to do it in Blueprints instead of C++ i will post my answer too, you can just look at the screenshot if you don’t want to read the description, i just created an actor and added a “box collision” (it also works with sphere collision, that is what you want) component, then just scroll the “details panel” on the right (by default) and click on the “+” icon in the “on component begin overlap” then it will create an event when the box overlaps something. then i cast it to a character wich is the default parent class to characters, you can cast it to something else if it’s different in your project, just be sure it have a character movement component, i get the component and change the max walk speed you can also change max swin speed (if it’s a boost for when you’re swimming) or crouch speed (for when you’re crouched) etc.
other actor->cast to character
as character->get character movement then promote max walk speed to a variable
from character movement->set max walk speed and put the new speed you want, i’ve promoted the new speed to a variable, you don’t need to
from set max walk speed-> delay: set how long the boost effect should last in the “duration” field
from character movement-> set max speed to the default speed (the one you get before boosting and promoted to a variable)
