Can't Derive from UAnimGraphNode_Base

I’m trying to make a custom animation blueprint node for some specialised blending. I’ve been using the Technical Guide, Rama’s tutorial, and the engine headers. They all result in the same compile error (using Rama’s tutorial as an example):

error : Superclass AnimGraphNode_Base of class AnimGraphNode_NameOfYourNode not found

If I write a class that does not derive from UAnimGraphNode_Base, but instead has a UAnimGraphNode_Base UPROPERTY, I get this error:

error : In SandboxGameMode: Unrecognized type ‘UAnimGraphNode_Base’

The funny thing is that I can reference UAnimGraphNode_Base properly, as well as all related classes, as long as I don’t use them with the U[…] system. I have tried this in a clean project, both with and without the deprecated ‘Classes’ folder compilation schemes that I’m guessing these examples were based on.

Edit

This problem was solved by Rama below. Unfortunately, it lead to another error, this time in the linking, that still prevents me from deriving UAnimGraphNode_Base.

Here are some replication steps for anyone interested. They assume the project is named “Sandbox”. I’ve used Rama’s code instead of my own, because I know it can be compiled without errors of its own.

1- Create a new Basic C++ Project through Rocket.

2- Open Sandbox.Build.cs (Source/Sandbox/) and modify this line to add the bolded section:

PublicDependencyModuleNames.AddRange(new string[] { “Core”, “CoreUObject”, “Engine” , “AnimGraph” });

3- Add these four files to your source (Source/Sandbox/):

AnimNode_NameOfYourNode.h

AnimNode_NameOfYourNode.cpp

AnimGraphNode_NameOfYourNode.h

AnimGraphNode_NameOfYourNode.cpp

4- Compile. Your should get 15 linker errors (unresolved externals), all UK2Node methods.


I’ve replicated the errors on two other Rocket installs, so it isn’t some kind of corrupted filesystem. Also, the methods triggering linker errors can be successfully linked outside of the class deriving them. This can be tested as follows:

#include "AnimGraphDefinitions.h"
#include "Kismet2/BlueprintEditorUtils.h"

...

UK2Node* node1 = 0;
node1->AutowireNewNode(0); //do not run, just compile, will crash spectacularly

This leads me to the conclusion that I must be doing something wrong. Somewhere I must not have added a dependency, or a header/library include. Hopefully these steps above can help someone determine what I’ve missed.

I finally solved the problem. You need you include an additional public module dependency, ‘BlueprintGraph’, that ‘AnimGraph’ seems to depend on.

I’m going to mark Rama with the correct answer because he got me 90% of the way there.

Dear Andrew,

#Build.cs

In your game Build.cs did you add AnimGraph?

 PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "AnimGraph"});

this is Source/YourGame/YourGame.Build.cs

#Header

And does your header have this at the top?

#include "AnimGraphDefinitions.h"
#include "Kismet2/BlueprintEditorUtils.h"

#include "AnimGraphNode_YourNode.generated.h"

:slight_smile:

Rama

I had the headers including properly, but I had overlooked the module dependencies. Thank you!

Hmm, it turns out that the problem is not completely solved. When I build the same clean project now, I get 15 unresolved externals all to do with K2Node methods. Am I missing something more?

you have these two includes?

#include "AnimGraphDefinitions.h"
#include "Kismet2/BlueprintEditorUtils.h"

I have nodes I build every time I recompile, so it’s not a beta6 issue,

please post your entire graph node .h and .cpp please

AnimGraphNode_NameOfYourNode.h

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "AnimNode_NameOfYourNode.h"

#include "AnimGraphDefinitions.h"
#include "Kismet2/BlueprintEditorUtils.h"

#include "AnimGraphNode_NameOfYourNode.generated.h"

//Whole point of this is to be wrapper for node struct
//	so it depends on it, and that node must compile first
//	for type to be recognized

UCLASS(MinimalAPI, dependson=FAnimNode_NameOfYourNode)
class UAnimGraphNode_NameOfYourNode : public UAnimGraphNode_Base
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(EditAnywhere, Category=Settings)
	FAnimNode_NameOfYourNode Node;

public:
	// UEdGraphNode interface
	virtual FString GetNodeTitle(ENodeTitleType::Type TitleType) const OVERRIDE;
	virtual FLinearColor GetNodeTitleColor() const OVERRIDE;
	virtual FString GetNodeCategory() const OVERRIDE;
	// End of UEdGraphNode interface

protected:
	virtual FString GetControllerDescription() const;
};

AnimGraphNode_NameOfYourNode.cpp

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#include "Sandbox.h"
#include "AnimGraphNode_NameOfYourNode.h"

/////////////////////////////////////////////////////
// UAnimGraphNode_NameOfYourNode

UAnimGraphNode_NameOfYourNode::UAnimGraphNode_NameOfYourNode(const FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
}

//Title Color!
FLinearColor UAnimGraphNode_NameOfYourNode::GetNodeTitleColor() const 
{ 
	return FLinearColor(0,12,12,1);
}

//Node Category
FString UAnimGraphNode_NameOfYourNode::GetNodeCategory() const
{
	return FString("Anim Node Category");
}
FString UAnimGraphNode_NameOfYourNode::GetControllerDescription() const
{
	return TEXT("~~~ Your Anim node Title ~~~");
}

FString UAnimGraphNode_NameOfYourNode::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
	FString Result = *GetControllerDescription();
	Result += (TitleType == ENodeTitleType::ListView) ? TEXT("") : TEXT("\n");
	return Result;
}

These are the test cases I’ve been working with. They’re 99% the same as your tutorial examples. The only parts that I changed were the ‘#includes’ (in the .h to add my USTRUCT header, and in the .cpp to remove the update the compilation scheme to beta6). I’ve also been working with some naked AnimNodes/AnimGraphNodes in another project; just the bare minimum to compile. They have the same linker problem.

#No .h in the .Cpp

Well one thing to note,

in your .cpp

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#include "Sandbox.h"
#include "AnimGraphNode_NameOfYourNode.h"

/////////////////////////////////////////////////////
// UAnimGraphNode_NameOfYourNode

You should not be including the .h file for the same-named .cpp file!

If you have to do that, something is not right, please remove that line and recompile and see if anything changes

#include "Sandbox.h"
/////////////////////////////////////////////////////
// UAnimGraphNode_NameOfYourNode

That’s the new beta6 style, since they’re working on removing *Classes.h files. If you create a new code file through the beta6 interface those #includes are automatically added. For example, a Rocket-generated SandboxPlayerController.cpp has the following #includes automatically added:

#include "Sandbox.h"
#include "SandboxPlayerController.h"

I had previously tried the old style though (in case that was the problem), and it didn’t fix the linking. I will try it again now, maybe I didn’t do it properly last time.

“That’s the new beta6 style, since they’re working on removing *Classes.h files”

ooooh interesting!

Thanks for the headers up on that. … ( :slight_smile: )

did you try my suggestion below

about

AnimationRuntime.h?

Rama

headers up

Thanks, needed a laugh right about now :slight_smile:

#AnimationRuntime.h

Try adding this to your .cpp

and try compiling!

#include "Sandbox.h"
/////////////////////////////////////////////////////
// UAnimGraphNode_NameOfYourNode
#include "AnimationRuntime.h"

Unfortunately, it is still broken :frowning:

I tried compiling with the *Classes.h method and no success. To check if it was some kind of library inclusion problem, I put the following in my SandboxPlayerController.cpp:

UK2Node* node1 = 0;
node1->AutowireNewNode(0);

UAnimGraphNode_Base* node2 = 0;
node2->AutowireNewNode(0);

I compiled the code without the broken files, and it worked. It could access that method, which is one of the linking error methods from the broken files. I did not run the code, as it would have resulted in a crash.

That means it is most likely a problem in the files, like you’re saying, and not a step I’ve missed somewhere along the lines like I did with the module reference earlier.

I’ve tried multiple variants of the files:

  • Both the USTRUCT and the UCLASS in the one file. (to avoid any problems that could be related to #include order (for example, Windows.h and winsock2.h))
  • Empty AnimNode and empty AnimGraphNode. (no methods, just the AnimNode UPROPERTY inside the AnimGraphNode)
  • Just the AnimGraphNode, using a pre-existing engine AnimNode.
  • Deriving from a pre-existing AnimGraphNode other than _Base.

Nothing solved the problem.

#Unresolved

Hmmm, I dunno then, if you’ve done the build CS and all the headers…

I’m going to have to wait and see what Epic says about this :slight_smile:

The build CS and the headers are the only things I can think of

I have no issues compiling my anim nodes every time, and I have explained the setup I use.

I’m not sure what other differences there could be between how our projects ar setup up other than the build CS

Rama

Thanks for your help anyway, I appreciate it.

Most likely I’ve not done some obvious little thing that needed doing to make this work. I’ll get some replication steps up when I get home if no-one else weighs in in that time.