[C++ Plugin] Create Unreal-like graph

Hello!

I`m making an Unreal plugin which contains graphical editor. I think the simpliest and most clever solution would be to use built-in Unreal graph. My question is: How to implement one and place it inside my window with Slate?

Here are some examples:

All I want is just a graph (without any nodes or blocks).

I found a few examples (AIGraphEditor.h), but I still don’t know how to implement graph in my plugin.

Best regards,

HRZ

have you checked the legality? last i checked you’re not allowed to use the editor or its code without permission, but i could have misread the terms!

Well, I send a mail about permissions. I hope Epic will have no objections.

You are free to use editor APIs… you probably already use it anyway as you making plugin, what you can’t do is use editor code and editor it self in distributed game you only can distribute runtime part of the engine with the game.

So as long as it is a seperate module and works only in editor not distributed game (by that i mean only editor part of you plugin) you are free to use it… besides you all you do is communicate with editor APIs and if you try to package code that use editor API you will have error, so you can’t do harm there. Remeber to mark you module as editor module and put in editor module only stuff that is needed for editor part of your plugin, user should not refere to it in there code or else they extending editor themselfs…

First it is importent to graphview works like text editor, it only purly contains node data which do nothing without runtime code, so you will need to create 2 parts, one runtime part that actully do things in game and 2nd graph editor part, but you can use any model you want, you just need to remember grpah editor it self is empty shell and node data which you can use to reconstruct some state from that ndoe data

Now there 0 documentation and whole thing is too complicated to describe it here, best way to learn is to take simpliest editor and try to mimic what is doing. most simplies example is sound cue and sound class editors. Graph editor is build in 2 parts, editor it self that opens when you open asset and graph widget, so those 2 parts are seperate places in engine source code, but oyu can hold it in one place in your plugin if you want.

Editor:

Graph (cpp files are in private directory):

First you need to learn how to make editor for asset, you need make class that extend FAssetEditorToolkit, in there you descibe widget contence of editor which will include the graph

Graph widget is reusable you extend it from base class UEdGraph and few other support classes. Most importent part of graph is Schema class, it descibes behavior of graph, creation of nodes, what can be connected to what and stuff like that.

You also need to create Node classes, remember that graph it self is descriptive, node class it self only decribes how node is structured graphicly, so you can make single node class which will adopt it self to something, for example Sound Cue has node classes that are seperate from editor and manipulate sound playback and they run in runtime and there one node class for editor only adapt itself to that sound cue node class which let you describe connections between them, SoundCue ndoe editor also have root node which is output node, it’s to related to sound cue nodes so it’s in sperate class.

In general practice if you want to use graph editor to manipulate some logical node network in gameplay you should use this model, make a node system for gameplay first (one that will work without referring to editor code) and then use graph editor and its nodes to manipulate it and use it to restore node network of gameplay nodes.

Can you tell what you want to use graph editor for? so i can give more tips. Sorry that you may not understand it >.< it very complex thing that it’s hard to describe in short and i also didn’t touch graph editors since more then half year. I really hope you have skills to deduce things from engine code since it really only way to learn it right now

AI graph is more customized graph, i didn’t seen it at all yet so you on your own here if you want to use it

2 Likes

Thank you very much for quick answer!

So, from beginning:

  1. Well, I’m 17 years old passionate programmer, but I understood the code from CueEditor Graph and I think I would be able to mimic it :wink:

  2. I’m creating plugin which allow you to make and edit dialogues ( using graphical interface ). To put it most simply: There is Actor object in game world which contains all data about itself and dialogues related to it ( structures ).
    Plugin’s window looks like this:
    99446-
    Left side: SListView with all avalible dialogue objects

Right side: Graph

Bottom(WIP): Node properties

When SListView selection change, plugin sould take necessary data from selected object and reload graph. I’m sure you can imagine this.
AI graph interested me the most becouse it looks similar (except logic stuff) to what I’m trying to accomplish:

.

^ It would be nice if user could also add his own functions to dialogues ( example: when this dialogue is triggered, some matinee plays)

Yeah, I thought about the same thing. :slight_smile: Thanks for all tips anyway!

Ahhh so you not plaing to use asset editor. Hmm blueprint comparator seems good example of non-asset editor use of graph ui. And indeed AI graph would be better here.

As for calling functions, reflection system is your friend here, you just need to look up all UFunction objects in memoery (in editor only ofcorse, in runtime you should have ready refrences in data) and you will have list of all of them, you can filter them down to once that have BlueprintCallable flag so they match blueprint compatibility. Note that this includes all C++ and blueprint functions as they equile in reflection system + it will also list parent function that got override, so you will need to solce this issue somehow. Then oyu can execute function using ProcessEvent

Param argument (which is void* so it accepts any type of data) need to be a struct of function arguments in there respective types in same order as they are declered in function (not in compled code function names and there arguments don’t exist, you wont be punished even if you use wrong data type there, but you either crash or you produce trash data). For more advance calling you need to use Invoke:

Which i never used and don’t know how to use it myself

Blueprint comparator? Can you post some source example? ( like CueGraph ). I thought a while about and I think assets won’t be a bad idea (
especially when one dialogue matches, let’s say, all guards in city - no copy, pasting in that scenario! Just one asset. :slight_smile: ). But that solution brings up a few more questions I have:

And thank you for your answer. :slight_smile:

Oh good to see tutorials on that matter, i needed to figure things myself for that :stuck_out_tongue:

You change double click (and genrally “open action” by overriding this in your FAssetTypeActions:

void FAssetTypeActions_YourAssetTypeClass::OpenAssetEditor(const TArray<UObject*>& InObjects, TSharedPtr<IToolkitHost> EditWithinLevelEditor)

UE4 holds all FAssetTypeActions for default asset types in single module so look there for examples:

Ahh your tutorial don’t cover FAssetTypeActions at all! those classes define how your asset looks like in content browser. As they are not UObjects, you need to resister (and unregister on unload) them manually with RegisterAssetTypeActions on module load

Here how Paper2D does that:

https://github.com/EpicGames/UnrealEngine/blob/dff3c48be101bb9f84633a733ef79c91c38d9542/Engine/Plugins/2D/Paper2D/Source/Paper2DEditor/Private/Paper2DEditorModule.cpp#L126

Note you need to access AssetTools module with FAssetToolsModule::Get() and from there call register

FAssetTypeActions temselfs are pretty simple and self explanatory, looking at it i think you should not have a issue to learn how to use if you just look how other assets are done. Here eveything oyu can override in that class:

Alright, first part ( to mimic CueEditor) is done. But, when I’m trying to compile, a lot of “redifinition; multiple initialization” and “‘struct’ type redefinition” or “inconsistend dll linkage” pops up in error list…, and I don’t know how to fix it. :confused:

click output log and copy here (with code formating ofcorse)

http://wklej.org/id/2775144/ ← too much text to paste it here.
It looks like UnrealHeaderTool doesn’t see my classes and structures. All errors occur inside my main generated module file.

Did you add “GraphEditor” module dependency? If you get linkage errors it is for 90% depency missing in build script, then you need to add module that where those functions are contained

http://wklej.org/id/2775524/

Something is wrong there?

Wait those are yours classes, do you have AdvancedDialogues_API before class name?

I am at beginning stages of learning about this as well.
The route I am studying so far is creating an empty window Tab, and spawning a SGraphEditor widget within window’s “OnSpawnPluginTab” function

You’ll want to keep note of this class:
C:\Program Files\Epic Games\4.12\Engine\Source\Editor\UnrealEd\Public\GraphEditor.h

Also, grab a copy of this PDF for reference:
https://de45xmedrsdbp.cloudfront.net/Resources/files/slateTutorials_westcoast-1963123470.pdf

Here’s a tryout I’ve just built, to learn this Slate stuff; a empty window on Editor with a custom graph node.

So this is really possible :smiley: How did you spawned SGraphEditor?