How to call function on AnimGraph C++?

UCLASS()
class TEMPLATE_API UAnimationInstance : public UAnimInstance
{
GENERATED_BODY()

public:

UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe))
void UpdateView();
}

I just want to call the method ‘UpdateView’ in the AnimGraph of my Animation Blueprint, which inherits from AnimationInstance.cpp. But I only see engine methods. My method is not visible. What’s the issue? If I do the same thing, but through Blueprint—by creating a function and setting BlueprintThreadSafe to true—it works fine. But it doesn’t work through C++.

You need to share the code you’ve written where you’re trying to call that function in C++.

The method should be accessible once you make an animinstanced based on your class. The function is accessible in the Event Graph

And if you state the function in the public segment like this:

You can also access it via a cast from the meshes anim instance

This guy calls the method directly in the AnimGraph, but he does it using a Blueprint function, whereas I need to implement it through C++. If you write “callfunction” when calling a method in AnimGraph so the engine function will be displayed, but I need my function to be there too, do you understand what I mean?

Inside of your character use a cast to get access to your class.

if (UAnimationInstance* animInst = Cast<UAnimationInstance>( GetMesh()->GetAnimInstance()))
	{
		animInst->UpdateView();
	} 

you also have to include your animation instance class inside of the character cpp

#include "AnimationInstance.h"

Example

The character needs to have a mesh set otherwise the cast will not have a mesh to access.

Not sure why you would specifically need a c++ call in conjunction with anim graph.

You can get the node directly as well if your anim instance is of type AnimationInstance (you custom c++ class)

Is not visible in the picture but Parent class NewAnimBlueprint → is MyAnimInstance

But it doesnt work for me.

Is you animinstance parent class = UMyAnimInstance? (can’t see the top right corner)

If so and it’s not showing up then try closing the editor and recompiling the project and running it. Maybe it needs to refresh the headers.

(post deleted by author)

I closed the editor and made a Build Solution. Still not. I even reinstalled the engine, it doesn’t help either. Here is the full photo showing the Parent Class

Which version of the engine are you running? Exposing the function is experimental in 5.4 if it’s an earlier version it might not be available.

5.5.3, but I tried on 5.4.4 as well


Notice the big warning on the right. Maybe it’s an option that you don’t have somewhere enabled?

The thing is when I create a blueprint function, I see it and everything is fine. But I can’t see it through C++. Maybe I have a problem with Visual Studio or Rider?

If you can help me, it will be a great happiness for me

Was wondering if play test was a reserved word that wouldn’t work, but it show up

I just have this in my header

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Animation/AnimInstance.h"
#include "AnimationInstance.generated.h"

/**
 * 
 */
UCLASS()
class RIDERHOT_API UAnimationInstance : public UAnimInstance
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe))
	void UpdateView(){ };

	UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe))
	void PlayTest(){ };
	
	
};

Tested out in rider with hot reload

But I realized that I have a problem somewhere and its not on the Unreal Engine side. Thanks, I’ll to search. I’ll try reinstalling VS and Rider.

What version of the engine do you have at the moment of testing?

it works in 5.4.
in 5.5 it doesn’t seem to show up, maybe Epic added a toggle for it in later versions?.

I’ll install 5.4 now for the sake of testing and try it, if not, I’ll continue looking for a solution

Found a partial solution

You can create a Blueprint Function Library where you can add static functions like this

The functions then show up in 5.5