- Unreal Version: 5.0.0
- Template: Third Person
- Project Name: MyProject
In this example the player will create a sphere by holding the left mouse button and every character that overlaps the sphere will trigger their heal method. The characters healing will have their material pulsate green.This example is a little weird, character's don't actually have health that increases, but it has a lot of useful snippets that I think can help in the future or be extended.
- UMaterialInstanceDynamic
- OnComponentBeginOverlap
- Cast to Character type
- SetScalarParameterValue
- SetWorldScale3D
- Update inputs
-
Add an input method. I added an Input action called
Heal
and bound it to the left mouse button. Edit->Project Settings->Input -
Update the M_Male_Body Material to have an if statement. See image below Content/Mannequin/Character/Materials/M_Male_Body
-
Create A new material to use for the healing sphere or use whatever you want. I made a simple translucent material, see image below
-
Add other ThirdPersonCharacter Blueprints to your Scene. *Content->ThirdPersonCPP->Blueprints->ThirdPersonCharacter
-
After the code compiles add the sphere mesh and material to the player character.
-
Update the sphere's collision presets to only overlap Pawns.
MyProjectCharacter.h
- lines 9-10
- lines 38-65
MyProjectCharacter.cpp
- lines 11-12
- lines 51-72
- lines 84-85
- lines 169-240
- OnComponentBeginOverlap
- FComponentBeginOverlapSignature
- UMaterialInstanceDynamic
- GetMaterial
- UMaterialInterface
- SetScalarParameterValue
- Good thread on creating dynamic materials
- Good Thread on IsA
- IsA
OnComponentBeginOverlap /Engine/Source/Runtime/Engine/Classes/Components/PrimitiveComponent.h Line 165
DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SixParams( FComponentBeginOverlapSignature, UPrimitiveComponent, OnComponentBeginOverlap, UPrimitiveComponent*, OverlappedComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, int32, OtherBodyIndex, bool, bFromSweep, const FHitResult &, SweepResult);
OnComponentEndOverlap /Engine/Source/Runtime/Engine/Classes/Components/PrimitiveComponent.h Line 167
DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FourParams( FComponentEndOverlapSignature, UPrimitiveComponent, OnComponentEndOverlap, UPrimitiveComponent*, OverlappedComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, int32, OtherBodyIndex);