Download

Quick question is this the best way to cast between two BPies ...

[FONT=Noto Sans]Just curious if this method is the best way. The “Get all actors of class” node does have a warning that its slow. So just wondering if there is a better way to set this up. The object I am casting to is not in this BP but in another one. So I cant hook up the object pin of the Cast node to anything in this BP - that is the main issue.

Zak Parrish does a tutorial that’s considered a ‘standard on Blueprint comms’. Most devs watch that (its a Livestream iirc)… Definitely Get-All-Actors can be slow, so you don’t want to place it in a Loop or run it on Tick etc. But the further you go with your project the more you’ll learn which classes need to communication. Approaches:

Easiest: Direct-Comms: Have one class spawn another so it automatically gets a reference to it. Or (in single-player) have gamemode spawn classes so it can set all the references inside the classes directly. Or store (house) key ‘shared communication variables’ in gamemode. Then you just need to cast to gamemode (not use get-all-actors etc). Tip: BP Global-Function-Libraries can also simplify much of this work.

Intermediate: Create your own Get-All-Actors etc. Add classes to an array (of actors) as they’re spawned into the game. This array can reside inside multiple classes or just gamemode. You can also ‘cache’ Get-All-Actors by assigning the result to an array once at game start-up… Or just very occasionally, so its not called too often (useful if you’re constantly creating / destroying actors you need to keep references to).

Advanced: Interfaces / Event-Dispatchers: Zak covers these in depth and they take time to explain so better not get into it here. But Interfaces particularly are a workaround for casting, as you can call methods directly on actors without casting at all. There’s a Get-All-Actors of Interface node to get references to these actors, which is less heavy a call. Event Dispatchers are for creating event driven gameplay and for ‘hooking into’ events for objects created dynamically at game-time (often used by classes or components to send messages / events to one another etc etc).

Great thank you very much !!!

No worries…

BTW: Gentle reminder about the panning widget material. No rush but please share at some point… :slight_smile:

Send me a private message and I will just send you the BPies. :slight_smile:
Include your email address so I can send a copy and paste of the BPies and wont be limited with number of characters.

Hi Clavos I cant seem to be able to reply out of my inbox in the messages area it looks like I have to subscribe to your profile first.
I will send you an email too.
I have included the BP for the Material setup in that long email I sent you.
I put a heading on top of each pasted BP text that tells you which BP it is below it.
Tell you what I will do a quick breakdown with screen grabs here in this thread in a few minutes then you can see exactly how I did that.
Its pretty simple actually.

Here is a breakdown of the setup: