Download

Connecting Blueprints with C++

I have created a level generator in Blueprints. Now I’m trying to create some rules to define some constraints such as “this type of block can’t be position next to other type of block”, etc. I have decided I’ll go into C++ with this because it would be just too messy to have such a big logic in Blueprints.
I have downloaded UE4 just yesterday, so I’m not quite sure what would be the proper architectural way to approach this.
Should I just create a GameMode class?
The class itself will have 3 public methods and it will hold no state. In other words, there should only be one instance of the class for all the Blueprints(singleton) or the class can be completely static.
Thanks in advance.

See my thread.

I would suggest adding sphere components to your actors, make them invisible, but if they ever overlap with something then insert whatever logic you need to to make them blast or warp away from each-other, just add your own function to the OnActorOverlapping delegate’s list (basic method in my thread). You could make the invisible sphere push w/e actors it comes in contact with as well, or you could have the object move itself out of the sphere’s influence. The BeginOverlapping event generally passes in a “OtherActor” reference so that your object can know what object has entered it’s space. You could use that reference/pointer to execute logic on the invading object as well, with a little math you could make the sphere push them out of it’s area. You could use the physics for that or you could just update the actors locations, that’s more of a gameplay/design question though. Aside from my thread which teaches how to list a function with (most)ANY delegate, the Documentation link in my thread has some code code for handling the overlapping of an invisible sphere already, exactly what you need.

I would also look into encapsulating all this logic/functionality into a component, that way it would be easy to extend any actor with the extra functionality. After all, UDK is well designed: encapsulation and code reuse are key features of C++.

PS: Whatever you do, don’t grab multiple actors coordinates and compare them yourself. Besides being a coding nightmare, unless you’re John Carmack you (arguably) wouldn’t be able to write it as well as Tim Sweeney has done already, it would introduce a TON of overhead to your game. Much easier to make an invisble “sphere of influence” and just delegate OnOverlapping messages to your class objects, let the engine do the work.

Thanks, but that wouldn’t solve my problem. What I need is a custom validator which will be executed in a branch which is spawning the actor I need to get spawned. The validator will evaluate the actor’s spawning position in regards to player’s spawning position and will either allow the spawn or not.
I have the code in Blueprints right now, but it’s a huge mess of links, branches and evaluations. I could easily implement that with like 30 LoC in C++.

Well, I say to use delegates because the blueprint system tends to rely on delegates for it’s events. If you have an event node in that blueprint, 99/100 it’s defined as a delegate in C++, no way around using them, UDK is event driven and that’s how it’s done, that’s how “event” blueprints are connected.

Anyway, I would suggest writing the C++ class to derive from the same type of object that is currently holding your blueprint.

PS: I wouldn’t mind writing it up for you, I could use the challenge, although I would need more information. PST if interested.