"CAST" FOR BIND DISPATCHER

Hello ev! :slightly_smiling_face:

I made a bp that takes all the most used bp’s refs in my project, to avoid having too many get actors of class x times in each of them, to keep everything lighter. So, this bp takes all the refs and transmit them via Blueprint Interface. Now the problems is when I must use refs on binds, because a bind needs a strong,persistent and specific reference while I write refs in run time as variables, and this is a problem, infact the variable results not compatible on bind even if it’s the same bp obj ref where the call dispatcher is done. Actually I “solved” itering each ref with “cast to” and in case the cast is not failed and “as bp i need” is valid, I set “as bp” as the variable for the bind. This solved both the incompatibility issue and all the error messages I had in the log regarding K2node.

Up until now I’ve worked to avoid CASTs like hell, in this case I found myself forced.

So, now my questions are : Is wrong to use CAST node in this way? And also, Is there a better way to solve this kind of issue?

Thank y’all so much! :folded_hands:

If Cast create a dependency that drags 10GB of textures or something like that along with it - then you MAY want to think about it. Avoiding it doesn’t always make real sense…

You can make something like an “interface” for the delegate. Just put it in the actor component, then you can call Get Component By Class and bind to the delegate in the component.
In this case, you don’t need to cast to actors. All you need is for them to have a component with a delegate.

1 Like

@PREDALIEN
let’s say I got into the habit of using it as little as possible because I knew it could compromise performance and that there were other ways to achieve the same thing. Leaving aside the cast, if I did as you suggested, wouldn’t the bp that takes and validates the refs be useless? And can a component really be the target of a bind? I thought that the targets had to necessarily be the bp that make the call.

Using the Create Event node you can bind events/functions from other objects to the delegate, not just your own.

1 Like

Probably I missunderstood what you meant for component. I’m a bit confused.

Actor Component blueprint:

Using:

1 Like

So it is no longer convenient for me to create dispatchers inside the bp that make the calls, but for each one I need, I should create a bp of type actor component and insert the dispatcher inside it. Is this what you meant?

It’s the first time for me with this kind of bp.

@PREDALIEN

Yes, you create one (or more if they return different parameters (different signatures)) component class and then use it in all actors where needed.

1 Like

Once created how can I implement them in the bp that need them? Like bpi? @PREDALIEN

1 Like

At this point in the bp that takes all the refs, I take both the direct actor object refs and the ref actor components, I take them all together and transmit them according to you? With variables in run time, won’t it give the same problem?

I didn’t quite understand you.

Can you show the code you got?

1 Like

I mean this I described at the beginning. I forgot to say, bps I’m talking about, are the same (dragged and dropped) for any level, but in debug mode, I just noticed they’ve a different alpha-numeric suffix. Could be this one the problem?



@PREDALIEN

It takes bp refs, add them in array, for each target send to it all refs. Then each bp filters and discard self ref. Now each of them have valid refs to use for binds, bpi eccetera…This was my idea.

You need to get all actors (base class “Actor”), and in the loop find the component with the dispatcher in them. You need to save references to the found component, not to the actors.

Can you clarify what exactly you are trying to do? The knot in my head is getting tangled… :melting_face:

1 Like

I’m trying to avoid having too many and repetitive “get actors”. So my idea was to have one single bp that takes all main bps refs and trasmit them to these same bp. For future use, for bind, for bpi eccetera. So get is done once for all, and each bp has the refs from the beginning. I kept this kind of ref because the target needed was “actor obj ref”. @PREDALIEN

So now my question is, if I have blueprints in common between multiple levels, and instead of spawning them once at runtime in the current level, I drag and drop them one by one in the various levels to reuse them, it’s still as if they are not the same, and therefore I have to do get all actors of class instead of get actor? Is this what are you telling me? @PREDALIEN

You can use soft references of actors instead, which will be chosen in advance. :thinking:
(Hard ones are also possible, but the actors must be on the same level)

At different levels there are different actors (even if (because) you copied them), they have different paths (reference).

You can (should?) put common actors on a separate level. Copying is evil.

1 Like

I have to choose whether to use soft references in run time, for identical bp but dragged and dropped in each level, or keep hard refs, keeping all common bp in a persistent level and then spawning them in run time, is this correct?

@PREDALIEN :face_with_head_bandage:

You need to create a separate level for common actors that are needed at different levels.

Then make soft reference variables of these actors and choose them in advance.

Then do a Resolve of the soft reference, and if the level is loaded (the actor exists) - you will get a hard reference on the actor.

I’m confused. I’ve never worked with levels before. In another thread I asked what I should worry about to best reuse the same bps on different levels, and I was told that I could just drag and drop them. Nothing else. I apologize if I’m being boring, but I want to make sure I don’t make things worse with my code and destroy months of work.