Event from actor-variable are not called

hello everyone,
i am trying to call events from an actor that i saved inside a variable. I find the actor through a linetrace from the mouse, basically its the actor that is currently under my mouse-cursor. I checked already that the variable gets set correctly. But neither the cursor-overlap nor the on-clicked event get fired. any idea what the problem is?

i wanted to use it this way, cause the actor can be from multiple classes and i would rather not dupliced the logic inside every class.


Sounds like the player controller is preventing it:

or, if you’re overriding the controller:

image

But ofc, the onClick event would need to be in the base class everyone inherits from (or you laboriously add it everywhere). That’s providing you’re using inheritance.


This will destroy the controller itself.


If you want the functionality in the controller only:


Ideally, you’d use an Interface here. When the player clicks, we send a message:

And each receiving actor (implementing the interface) can decide what happens with the click.

The best part is that if you send a message to an actor with no interface or implementation of the pertinent Event/Function, nothing happens - the call will fail gracefully.

Blueprint Interfaces are created exactly for your problem, learn about them and use.

More if all actors called can have same parent (are same type at its core/basic functionality) then make parent class with all communication needed and create child classes out of it.

There is also way of coding it all in blueprintable components then dropping such components at actors that need functionality, but this not always is possible to code as components are quite limited.

So with blueprint interfaces, you code your stuff once (in blueprint interface), then add that interface to blueprint actor class.
Then when you want to trigger event inside it you cast to INTERFACE (and not blueprint class) and call code.

Ps.
Sorry i am blind you are using interfaces . Or that was post from Everyone. I need cafe to wake up.

You’re good! OP has an Interface:

But are they using it?!

Thank you for all the good information. Yeah i knew about interfaces, but still not sure when to use them over other communication options. Mostly i just saw that variables showed of events too and got curious if thats another method of communication between bp’s.

I am not sure what you mean by this. Can you implement functions inside a bp-interface? I searched around the web/youtube but i have not seen one tutorial showing off how to do that. They get always implemented inside the bp that implements the interface. Can you link me any tutorials how to do what you propose please? Thank you for the infos ^^

My last example shows precisely what is needed.

not sure when to use them over other communication options

You’d use it when you need to talk to numerous unrelated classes in the same fashion; this:

i wanted to use it this way, cause the actor can be from multiple classes and i would rather not dupliced the logic inside every class.

There would be no duplication and no casting. Especially when you inherit the interface and its functions’ implementations.

Can you implement functions inside a bp-interface?

You cannot, implementation is in the actor.

Ok but then i am a bit confused.
Right now i have one set of objects “vegetations” with the master implementing the interface, and all individual plants using those implemantations just fine (basic inheritance).
And i have other objects “construct-Proxies” that also need basically the same exact delet-functionality, but are not childs of vegetation-master, as they do not need any variables that are stored in that parent. So as far as i understand interfaces i still have to implement the same logic inside the proxies once more.

Or can i somehow implement the interface-functions inside the player and pass that logic through to the other actors implementing the interface?

Yes, you’d need to implement it again. But that’s, generally speaking, desired functionality.


How about having a base class that does nothing and has no variables - just the interface and function implementation that everyone needs. This way all and any inheriting classes can take advantage of that.

You can reparent existing classes:

image


One of the goals of the Interface is to send the same message but execute a different result. So it may not be a perfect use scenario and you could get away with just inheritance from one single parent. But then you may end up having to cast all over the place :expressionless:

I am bit rusty with blueprints (waiting for verse in ue5).

Now i remember that you cannot put code directly into interface.
However i made function library (make only one of them else you risk cyclic references and its pain). And the i added call to function in blueprint interface implementation.

There was also way with blueprintable components, that looked for parent/owner and cast to interface etc. However it was some ugly code for not much gain.

I had similar problems to one you described, but cannot remember exact working solution, ie. i remember what i tried just cannot remember what worked.

So i looked at all the actors i have again and i realised that the construct-proxy has exactly the same information that i have on the “placeable-object-master” from whitch i inherit into the vegetation-master.

Long story short, i could simply reparent the proxy to the highest parent, implement the deletion code there once and all objects i want to be deletable are now deletable XD
Sometimes rechecking your designs can help <.<

thank you both again for your help, helped me wrap my head around this whole thing a bit more.

1 Like

duck

I am happy to be rubber duck. :wink:

2 Likes