Call function on undefined blueprint?

I am trying to make a system where, using a line tracer, I can make the player interact with objects, however, it seems that the only way to call a function on an object is by dragging in a reference to the exact object, therefore meaning it is impossible to call a function on an actor that is found via a line trace?
If anyone has a method for this, it would be most useful :slight_smile:

The easiest way is to use game tags. Your blueprint can set a tag on the Hit Actor, so that in case that actor has a blueprint that checks if it’s been tagged in a specific way it will perform some action accordingly.

The easiest way to do this is with a ‘cast’ node. There is an example in this little tutorial I did:

You are basically finding out if a thing is of a particular type, so you can operate on it as that type if so.

A more advanced workflow is something called Blueprint Interfaces:
https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Types/Interface/index.html

You could create a ‘Interaction’ interface and add a function to it called ‘OnInteract’. Then add that interface to any Blueprint that you want to interact with (under Blueprint Props), and you will be able to add the OnInteract event node in its event graph. Then in your pawn, when you do your trace, try using the OnInteract ‘message’ node on the thing you hit. If it implements that interface, the event will fire in it. If it doesn’t, nothing will happen. We will certainly have a tutorial for this soon, it’s easier to see in practice, but for now casting will certainly get the job done!

THANKYOU this sounds perfect! :smiley:

Casting implies that you know to what to cast, so that is not really useful. The interface approach is indeed a good way to go, but implies a software design that is usually not there in garage studios or 1-man teams :slight_smile: I’ve been playing with interfaces and looks promising, still digging on their performance side that isn’t clear to me at this time (if you can give out info… I’d appreciate!)

The answer is interfaces.

Create a blueprint interface where you define the functions you need, then implement it in the actors you need to be able to call them on.

Then you can call the functions from other blueprints.