Download

Is there such as thing as a Code Node?

Hi all,

I’ve been using Blueprint for a few days and coming from a programming background I find that although Blueprint is really good at interfacing with the engine, there are some things that seem to get complicated very quick.

I know that C++ can define custom nodes, but is there something like a ‘Code Node’?

What I mean by this is a node with a small text box you could type a function definition into and as you add the parameters, the coloured dots appear on the sides of the box ready to be connected.

It needn’t have a full C++ command compliment, but something with simple maths and flow capabilities would be good and could condense some very complicated math / decision making networks without going completely hardcore programmer on you. Should also allow it to be stored inside exported blueprints.

Does anything like this exist and I missed it?

[EDIT] Added a post in the Feedback forum and a poll Link

Regards,

Lee Page
TeraBit Software

I’m not qualified to answer the question, but this would seem to be the point of blueprints. You can create functions in a blueprint that are essentially condensed networks of nodes. I think having a node created in c++ is great, but I personally see no reason to have a node that takes in code as well.

So maybe what could help are blueprint functions?

Blueprint Functions do help with the complication of nodes, but it would be easier to have a couple of lines of code take on a complicated task rather than drilling down to nested networks. Blueprint Functions are the next best thing I agree.

Regards,

Lee Page
TeraBit Software

Yeah I actually wanted to ask the devs about this too.
It would be really great to have a code node so we don’t have to mess with c++ for something relatively simple… even if slightly slower than using the “native” nodes.

I love blueprints and all but the main problem I have with them is that it can take you like 20+ nodes with complicated branching just to do something that can be done in a single line in C++! :rolleyes: you end up with a complicated-looking thing that can be kinda hard to read by others sometimes.

It would be quite useful, speaking as a programmer, to not have to go down into the source code just to add a fairly simple blueprint node. I don’t know if anyone’s used Grasshopper3d, but it had a C# component that you could just define a bunch of inputs and outputs and do whatever you wanted.

That being said, C++ might be overkill for that, I know some people are working on implementing some scripting languages, which would be a lot easier to use for things like that, but maybe C++ would be do-able.

Just add a new C++ Class and put the 1 function you need in it. Then make a blueprint extending from it in the Editor.

That’s true, you can do that. But it seems like a lot of work! After you go to the trouble of opening Visual Studio and sorting it out there, recompiling, get the new node, find something doesn’t work, go back, sort it out, recompile, reconnect the node.

Then there is debugging. If it is part of the node system, you could have it step through the code snippet while still in Blueprint and fix it there.

Think of c++ to be one end of the spectrum, Blueprint to be the other, “Code Node” sits in the middle for Anyone that can do a bit of programming, but don’t want to deal with full blown VS.

If you want to make it even more user friendly, have a choice of Basic or C for the syntax, as mentioned above, it probably only needs math, string handling & flow control and a few other bits to be really useful.

Regards,

Lee Page
TeraBit Software

Although its not ‘code’, you can check out the (experimental - so not finished or fully supported yet) MathExpressions plugin. This lets you specify a mathematical expression as a single Blueprint node using a standard notation. The node automatically generates inputs & outputs etc.

Just tried it. It does some of what I’d like to do, makes it easier to set up maths. But it still uses nested nodes, so is kind of like a specialised Blueprint function in that respect. :slight_smile:

Probably easier to show you what I mean rather than describe it: (Disclaimer: Rough Mock Up) :wink:

http://s3.amazonaws.com/Blitz/CodeNode.png

Not intended for ‘Monster’ code, but small sections that would be unwieldy as a node network.
(Edit: Yes I know the code is a bit wonky :smiley: )

vs

https://s3.amazonaws.com/Blitz/Blueprint2DCircle.png

I mean, can you see what the hell is going on in that network. Yes, you can turn it into a function and clean it up, but it took several times longer to make the network than it did to write the code, and it’s relatively simple code, and it will take the same productivity hit every time I need to modify it in some way.

Regards,

Lee Page
TeraBit Software

Yeah those are essentially two ways of doing this:

  • Scripting: faster to compile, but another language to learn and probably slower than C++. May be difficult to interface with the rest of the Engine, but probably easier for “pure” math or logic functions. May impact performance on repetitive tasks. Needs an additional bit to do the compilation (Lua, JS, etc…). Lua is not my favorite language, but it is lightweight to implement and it can be statically linked with the engine (i.e. can be multiplatform), whereas JS usually requires a large engine (e.g. Spidermonkey or Gecko)

  • C++: May be a bit slower to compile, however I could foresee a code generator that creates specialized classes with just one function. Performance equal to rest of engine, may be a bit more difficult to debug (no VS, although there is an Output.log), can access rest of Engine as well as hand-crafted code.

An interesting suggestion. As a C++ person myself, I could see it being more interesting in some cases. I do use blueprints for overall game logic, and C++ for more heavy duty stuff.

Perhaps make a poll in Feedback as a feature request?

I don’t think it would need to be as fast as pure compiled C++ to be honest. I don’t even know if Blueprint is actually compiled or is interpreted, but either way, actual compiled c++ would be better for heavy duty stuff, and there is a means to do that.

The aim here is simply to reduce complexity and increase productivity. So a simple interpreted script language with ‘C++’ syntax (so there’s nothing else to learn) with some additional .NET like string handling would work wonders.

In fact you would only need maths, flow control and string handling to make it really useful as a quick custom node.

Added a post in the Feedback forum and a poll Link

While not allowing actual c++ code or compiling the code, I have done some testing of integrating a javascript interpreter to allow javascript code nodes to be added to a blueprint. Basically I have created a script engine component that can be added to a actor and then that component has a number of blueprint callable functions in it. Most of these will execute a piece of javascript code that is passed to the function/node as a string. One thing that I haven’t been able to do yet is allow parameter pins to be added to a node dynamically. So instead I have various functions/nodes that each take different number/types of parameters. There is also some nodes that will just set a variable in the script engine context. Each script engine component has it’s own context, so once a variable is set, it can be accessed from any code node in that actor’s blueprint.

I did make a post about it here but there hasn’t seemed to be any interest. Another point is that as it is interpreted the speed isn’t going to be the fastest.

Also at the moment it isn’t easy to edit/add code in a blueprint as there isn’t any text editor window, so each string just gets a single line text box. So I have been writing the code in a external text editor and copying it across.

I hadn’t actually seen the math expression plugin as I have so far mainly been using my component for math expressions.

100% do want c++ nodes.

Looks like different approaches to obtain the same thing. :slight_smile: I envisioned typing into a multi line text box on the node itself and the UI may need tweaking to allow this I suppose.

I don’t think that speed is so much of a problem, as it’s not like you’d have masses of code in a single node.
The example above shows how some concepts lend themselves to code rather than node. :wink:

If it could be compiled and still maintain the ability to debug inline with Blueprint, that’d be even better, but I suspect to make it portable, you’d need a minimal interpreter. You could probably outsource it to .NET (as it could compile itself), but would only work on platforms with a .NET runtime.

Regards,

Lee Page
TeraBit Software

Being able to edit the code in a multi line edit box in the node would be much better, but as far as I can tell there is no support for multi line text boxes in the blueprint editor at the moment. So that would need to be added, and I haven’t got to looking into how to add features to the editor at all yet.

What I have done is integrate the tiny-js javascript interpreter: https://code.google.com/p/tiny-js/

The limits of having only the single line text editor and not being to add parameter pins to a node dynamically, are annoying but it is still usable. I had thought about looking into if I could add support for dynamic parameter pins, but as there didn’t seem to be any interest in the component, I haven’t bothered. As just having a set of function template nodes is enough for myself at the moment.

I think it’s because the example you posted didn’t immediately appear to be much easier than the node equivalent (partly because you had to supply the code as a string from a separate node and without dynamic pins).

Which is a shame really, because it’s a nifty accomplishment! Half way there!

Yeah my example wasn’t the greatest.

Not sure what you mean by the code having to be provided by a separate node though. Maybe it is less clear as to what nodes do what than I thought. Basically in the pictures, the Int Script Function nodes are executing the code that is set in the script input (in this case I’m using the default value text box). The Int Script Function node is one that takes no parameters and returns a int. There are also nodes that take various types and numbers of parameters and have different return types. But of course having dynamic pins would be better.

Ah, yes I see now. It’s a tough deal having the one line code thing. I didn’t quite follow what was going on :confused:, I can see what you mean now… :cool: