Plugin Module Dependency

Hi,

I’m trying to write a plugin that will extend the editor by allowing creation of a custom asset(something like Sound Cue).

Plugin has two modules, runtime module and editor module.

In runtime module we wrote a class UStory which mimics USoundCue’s behaivour. We’re having issues because in Story.cpp we had to include StoryGraph header which rests in the editor module.

This caused circular dependencies between modules. As far as i know runtime module shouldn’t depend on editor module.

This is what UStory class looks like.



UCLASS()
class UStory : public UObject
{
	GENERATED_BODY()

public:
#if WITH_EDITOR
	UStoryGraph* GetGraph();
#endif

#if WITH_EDITOR
	void PostInitProperties() override;
	void CreateGraph();
#endif

private:
#if WITH_EDITORONLY_DATA
	UPROPERTY() UEdGraph* StoryGraph;
#endif

};


To fix the problem we decided to create UStoryGraph object in runtime module instead of editor module and add a setter function to UStory class.
So we created the StoryGraph object inside the UStoryFactory::FactoryCreateNew(in runtime moduel) function and call the UStory::SetGraph function. We also had to change GetGraph’s return
value to UedGraph* because we can’t depend anythin on the editor module.



class UStory : public UObject
{
	GENERATED_BODY()

public:
#if WITH_EDITOR
	UEdGraph* GetGraph();
	void SetGraph(UEdGraph*);
#endif

private:
#if WITH_EDITORONLY_DATA
	UPROPERTY() UEdGraph* StoryGraph;
#endif

};


It didn’t solve our problems, Unreal Editor crashes every time UStory::GetGraph gets called. Does anyone have a better idea, or why ue4 crashes?

The way the engine types do this is to just forward declare the type of the editor only property (such as a UEdGraph*), but not actually do anything with that member that requires the type definition (such as calling methods on it) in the runtime module. The property is simply put into the runtime class, guarded with the editor-only preprocessor, for the convenience of having it embedded in the object. All use of that property is contained within the editor module code. That way there should be no need for a dependency from runtime to editor, which as you say needs to be avoided.

You don’t show how you are using your UStoryGraph, but if it won’t exist at runtime then you should avoid putting it in your runtime module.

@kamrann Thanks.

We did it like you said to prevent dependencies, but engine kept crashing, it turns out crashing had nothing to do with Plugin dependencies. There was a bug we missed.