Can I add animation notify using only C++?

Hello. Unreal Developer !
I can not speak English very well. hope you understand.

My question is,
Can I use C ++ only to add “Notify” to the montage and receive events from this “Notify”?

If this is possible,
Could you explain how to implement it?


https://answers.unrealengine.com/questions/440602/custom-animnotify-in-c-uanimsequencebase-is-null.html https://answers.unrealengine.com/questions/231681/my-uanimnotify-custom-c-class-received-notify-wont.html https://answers.unrealengine.com/questions/441017/how-to-get-character-within-uanimnotify.html https://forums.unrealengine.com/development-discussion/c-gameplay-programming/45844-is-it-possible-to-run-c-code-from-an-animation-notify?74606-Is-it-possible-to-run-C-code-from-an-animation-Notify=
This is what I found when I did a search, and I think it seems to be possible to implement it.

I want to implement,

I want to add “Notify” before playing montage and receive an event for “Notify” I added while montage is playing.

i need to add “notify” dynamically depending on the data in the CSV file( or ini file ).



To implement this,
Create a new class derived from UAnimNotify or UAnimNotifyState,
Also,
Should I also create a new class derived from UAnimInstance?


If you know about this, please feel free to reply. thank you.

I solved this problem.


void TEST::add_notify_in_montage(UAnimMontage* montage_in, FString notify_name_in, int32 frame_in)
{
	if (notify_name_in.IsEmpty())
		return;

	class UObject* AnimNotifyClass = NewObject<UObject>(montage_in, UCustomAnimNotify::StaticClass(), NAME_None, RF_Transactional);
	int32 my_index = montage_in->Notifies.Add(FAnimNotifyEvent());
	FAnimNotifyEvent& new_event = montage_in->Notifies[ my_index ];

	// Here you set the necessary information for the Custom Class.
	// I need "Notify" index and the name I defined.
	UCustomAnimNotify* notify = Cast<UCustomAnimNotify>(AnimNotifyClass);
	notify->set_notify_name(notify_name_in);
	notify->set_notify_index(my_index);
	
	new_event.Notify = Cast<UAnimNotify>(notify);
	new_event.Link(montage_in, (float)frame_in / ANIMATION_FPS);
}
2 Likes

You can also implement “NotifyState” in this way.
I created “UCustomNotify” using “UAnimNotify”.
You can implement “NofiyState” any number of times by using “UAnimNofifyState”.

2 Likes