Creating Animation Notifies from C++

I am creating a plugin which would automatically create animation notifies on all selected animations on a button click with naming and frames data extracted from a DataTable. The notify is a custom notify which has a property NotifyID and it is unique to every instance of the notify. This notify is supposed to print its NotifyID in its Notify method, which is working. The plugin is doing what it is supposed to do, only with a weird (but understandable) bug:

When I create the notifiers with the plugin button, all those notifies would only work during the editor is open, but they convert to a simple named custom animation notify when I restart the editor or right click and select reload on the anim asset.

BUT

If I create the same notifier from animation window, it remains consistent and works fine.

With some debugging I noticed that there is a difference between the path of the ones that the plugin is creating from script and the ones that I create from the animation window:

Plugin created notifiers’ path is transient i.e. “/Engine/Transient.CustomAnimNotify_X”

And the ones created from the animation window have the path “/Game/AnneAnimatinos/Uniclass_shot01_Anne_IK.Uniclass_shot01_Anne_IK:CustomAnimNotify_X”
(X = index number)

Here’s my notifier creation code:

UCustomAnimNotify* customNotify = NewObject<UCustomAnimNotify>();
						customNotify->NotifyID = audioName;
						customNotify->AddToRoot();
						customNotify->ClearPendingKill();
						
						UE_LOG(LogTemp, Warning, TEXT("CustomNotify path name: %s"), *customNotify->GetPathName());
						
						
						FString newName = FString("DialogueNotify");

						int32 NewNotifyIndex = animAsset->Notifies.Add(FAnimNotifyEvent());
						FAnimNotifyEvent& NewEvent = animAsset->Notifies[NewNotifyIndex];
						NewEvent.NotifyName = FName(*newName);
						NewEvent.Notify = customNotify;
						
						NewEvent.LinkSequence(animAsset, animAsset->GetTimeAtFrame(frameNo));

I think the transient thing is causing the problem. Maybe there is a way to use the same functions that the animation window uses to create notifiers.

Any help would be greatly appreciated.

I think setting the Outer when you call NewObject() is what you want. By default it points to the transient package. Try supplying the Anim Sequence the notify belongs to as the Outer param to NewObject()

Thank you FableBen! This was the solution.