Download

Interfaces not sending messages (trying to replace casts with a messaging system)

I’m trying to eliminate all the casts and getactorsofclass() nodes from my projects first level. I have my HUD class BP for my levels gamemode BP doing a 5-6 sequence executions with doOnce() nodes that fire off setting subtitle text in the widget the hud creates (and has to cast to) based on trigger boxes (casted to), the main character (casted to), multiple actor BP’s (casted to) and so on and so forth.

Now I’ve watched and followed Johnathen Daleys “Creating Gameplay Systems using Advanced Blueprint Features in Unreal Engine” as well as glanced over his new “Scripting a FPS in UE4” and after watching the adv. bp. one again I realized “Hey this is just like Unitys messaging system” (bad word I know). I’ve gotten so used to BP’s that I’ve not had the time to learn c++. Anyways.

I tried creating an interface for my first dialog sequence which plays the dialog cue and sets the widget text when a trigger box is beginOverlap() (was checked Previously if the triggerbox has a bool set to true every tick and then branched to play the sound and set the text. It worked by) and putting them in both of the BPs interfaces.

I tried every combination of a simple no IO message, a fake custom event (never fired on the HUD side) with just an input I tried bool in and out, ive promoted the bools on both sides every which way.

It made me think of doing Peter Newtons basic AI tutorial and binding events with an event dispatcher. Is this more what I’m looking for, a messaging system a cue system… someway to prevent doing rediculously weird and numerous (from a programming view) casts.

My scene of 50k tris and about 15 draw calls is getting 35-40 fps on epic on a GTX 760 Ti. Usually a similar scene would be 80-120.

In my trigger box I see it firing across the nodes EventBeginOverlap() -> Set at_area_one == true -> (tried both interface call and regular and a simple message) interface[x] -> delay(0.2f) -> DestroyActor()

But in my HUD class which currently holds all the scenes logic (dont ask why, just rapid prototyping and im the GUI guy on the team turned generalist) I go from event tick → interface[x] → playsound() → … Now that works just fine it fires through and plays the sound every tick, hence why I tried an interface with a bool in, a bool out, a bool in and out, a bool in and out connected together on one sides function, on the other, on both, with conditons on one side, on the othrer, on both.

No cigar.

Any tips to reducing casts? This is more hassle than its worth at this point but to re-write it would leave my team in the dust for this level for a few days. What I do have works, its just killing performance and its our primary hook scene so even more and more is getting added.

http://i.imgur.com/nW4rEtb.png the last setup I had tried, another simple bool in.

http://i.imgur.com/6nFXXLO.png my HUD class for this level. The mess I’m trying to optimize. No less than 6 casts and getActorsOfClass( ); to set 7 tutText subtitle lines in the single widget it adds to viewport and the 3-4 audio cues it plays and then spawn a few AI 1 at a time.

TLDR: NO matter what ways I try I cannt get a BPI from a trigger class to a hud class to work. It either plays the sound every tick (going right through the interface node) or doesnt play at all even when conditions are met, or there are no conditons, or conditions are manually set.

I do realize at some point I’ll have to rewrite all this logic in the proper way (not all this stuff in this hud class lmao) but even then, these casts from player controller[some actor] -> hud / widget kill me. They dont make sense. Coming from a Unity C# background and a very light C++ knowledge background.

Hello,
cast to maybe not your issue related to : https://forums.unrealengine.com/showthread.php?49895-Is-casting-expensive&p=167011&viewfull=1#post167011

To eliminate massive “cast to” and especially “get all actors” (which does a lot of useless work especially if you don’t use loop with break with big arrays) i use to set references on spawn / event begin play (even with an array set on spawn to differentiate same type of blueprints, using an int set in blueprint set equal as array index to find the right element, for example in a grid of blueprints) with regularly called actors.

One thing usefull would maybe to replace all your tick events by custom events / functions called only when needed, on click / over / any player action (not sure about what you can do as i don’t know your set up but the less you tick, the more it goes fine.)

I started rebuilding the logic on the level BP, the gamemode BP and individual actor BPs and keeping everything posible off the HUD bp. My FPS went back up to normal.

I guess I still have to wonder how to create a messaging system in Unreal so that say OnActorOverlap(SendMessage(Overlapped)To[BlueprintX]) and then in BlueprintX onMessageReceived(Overlapped) execute this string of nodes.

Since I’m using a gamemode and HUD for each level, thats alot of casting and cast failed debug strings to write out and nodes to make. Less than coding it sure, but I must be mistaking the use of EventDispatchers and BlueprintInterfaces for creating a messaging system because I cant get anything higher than the tutorials integer counter use of a BI.

Edit: I see what you mean about using reference variables, was confused by that statment at first. Never thought about that, the BP, UE4 aPI is brand new and C++ fairly new to me. So the proper way to go about this would be moreso setting variables of datatype bleuprintX and then using them to build functionality instead of casting all over the place or holding all the logic in 1-2 BPs?

Loading... 290mb. feel free to take a look (non commercial use only guys its not all CC-0 content), thats as of this morning when I started to rewrite, but if you open 01_TutLvlHUD hud class bp I left what I had before. The big mess I posted above.
s