C++ samples / training?

I’m starting a new project and would like it to be in C++ as much as possible.

Where is the C++ training material, and most importantly, working samples? For instance:

  • How to trigger an existing animation from C++
  • How to create a new animation curve & playback from C++
  • How to set a morph target weight from C++
    etc etc

The docs seem mostly focused on exposing C++ to Blueprint. I’d like to actually do the things I mentioned above.

Thank you. :slight_smile:

Do you know C++ ?
Do you know how Unreal assings things? (UPROPERTY,UFUNCTION,etc)

There are things that are better to be done in the editor, like creating animation curves/timelines,
setting up an actor with skeletal meshes, scene components, colliders, etc etc)…that setup is better to be done in the EDITOR and then you access from C++ because if you want to make an animation curve a pure coding you must enter each keyframe with tangents, etc… doing it via code is just insane.

Then understand different actors/components to know how to invoke in C++.

When you use a blueprint node, if you hover it with the mouse it will hint you the origin of the node to be used in C++.

I will show you some examples:

image

you can see that getWorldDeltaSeconds comes from gameplaystatics

then in your IDE you type gameplaystatics and it will suggest and you continue:

image

if your ide dont add the include for you you must do it:

#include "Kismet/GameplayStatics.h"

another example:

image

you see it uses Kismet Math Library and has 5 inputs and 1 output then
type something like kismat and if you IDE is good enoug it would suggest:

image

after UKismetMathLibrary you add :: and will suggest all the functions
and type: mapclamp and will suggest:

image

then:

objects in unreal start with U so you want to set a morph target weight
the object is a skeletal mesh, right? ok… you can google USkeletalMesh and
unreal documentation will popup with the info…

is a skeletal mesh component? lets type uskeletal and see what happens:

image

ok there is it…lets find out morph:

image

ok there is it

image

this is what it asks then:

image

Hope it helps!

1 Like

Wow! THANK YOU Eldany !

Yes, I know C++, and the UPPROPERTY / UFUNCTION things are explained well in YouTube tutorials, I understand that part as well.

I’ll try out the things you suggested, thank you for those tips & tricks!

What I was doing, and it wasn’t working, was that in the Character::Tick( ) function, I was doing the following. I thought maybe I was doing something wrong, but based on your message, seems like I was actually on target (no pun intended).

Any idea what could be wrong? I just made 2 spheres in Maya, scaled one up in Y, made a blend shape, exported FBX. I didn’t put a skeleton in it, but in the Editor I can see and move the morph target weight, and it does indeed stretch.

void ATestCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

USkeletalMeshComponent* mesh = GetMesh();
mesh->SetMorphTarget(FName("pSphere2"), 1.0, true);

UE_LOG(LogTemp, Warning, TEXT(" INSIDE CHAR TICK !! " ));

}

1 Like

Hi Eldany,

Regarding your comment on using blueprints as much as possible, I agree in general.

In my case I do think I need to set morph targets from C++ because these morph targets are for mouth shapes, and I don’t know ahead of time what will be spoken. I may not really need to create animation curves, I was just wanting to set the mouth shape on the ACharacters’s Tick() function. I wanted to do it in C++ because the knowledge of what the mouth should do will likely be coming from C++ as well.

Thanks.

Just for the sake of completeness, (even though your answer was awesome), I don’t see any C++ samples anywhere. Looking in: C:\Program Files\Epic Games\UE_5.3\Samples all I can find is a Blueprints/ folder, and even that is *.uasset. There are NO Visual Studio + Unreal Project working samples AFAIK.

Correct?

I have used this project as a sample to understand c++ Action RPG in Epic Content - UE Marketplace
but it 4.27, should be upgradable though.

That page says “Not for Sale”, can’t seem to download it.

you can create a UPROPERTY(bluerpintReadWrite) USkeletalMeshComponent* myMesh;
in the header and in begin play function (blueprint side) you just take your skeletalmesh and set it in the C++ variable so it will keep stored.

then in the tick function you can put something like:

if (mymesh)
{
     mesh->SetMorphTarget(FName("pSphere2"), 1.0, true);
}

anyway you are just hardcoding the morph value there…is it just for testing I suppose

I think trying to make everything from C++ is not efficient and takes more time.
I know you can call the blueprint skeletalmesh from C++ but why not just assign in beginplay from the BP if it is just once? its a lot faster to do and then you
have access from C++ all the time :slight_smile:

oups, it actually this one, i just checked they added a 01 at the end of the link…