Hi all,
So I am trying to use a reference with an interface, kind of new to interfaces and although I have some of the basics covered, I am still having issues to a few things.
So my problem is I am making Behaviour tree tasks, and instead of “casting to”, I would rather have the interface that references the AI it is attached to in the AI character. That way, I don’t have to “cast to” from each AI separately.
If anyone knows the correct way of setting this up, and doesn’t minding explaining the step by step, and the reasons.
Thanks!
There are two reasons to cast:
-
So we can check this actor is of type X
-
So we get ‘get inside’ the actor. Once we know what kind of thing it is, we can call a custom event inside etc.
The whole point of BPIs, is you can make a call on an actor, without knowing what kind of thing it is. It might have an event to handle the call, and it might not.
So, you’re right BPIs is the way to avoid casting.
For example, you might have 5 different kinds of AI, and you want to implement a ‘return to base’ routine. In your BPI, you define the ‘Return to base’ event, and in each of the AIs, you catch the call and might implement something entirely different.
The point is, you only have to tell them one thing, return to base.
Does that help?
I understand that is how it works, I probably didn’t explain myself clearly enough.
I want to know how to set up an interface that says, Hey I am an AI character, then in the BTT, I want to use that interface to replace the CastTo node.
So I can have 1 or 2, or 100 AIs using the same interface.
I don’t think you can use it directly in the BT, you would need to use it in the character, or in a task or decorator.
If you’re already using a cast on a ref, then just call the BPI on that ref, no?
The interface won’t be in the Behaviour tree. It will be used in the Behaviour tree task event graph.
So at Event receive Execute AI, the next node would be Cast To(Whatever AI character)
But castTo only pulls one ref. If I replaced that CastTo with an interface Then every Ai I use the interface in will use that BTT.
So instead of making 10 similar BTTs, I can have 10 AI share one BTT.
It won’t do a cast to self. Besides, that is not what I am asking for!
I might be missing the point totally, but do you mean:
( or whatever the call is… )
I tried setting it up like that, but it won’t connect to the target [self] input in the BTT node, and it darkens, meaning it won’t accept it. I probably haven’t set up the interface correctly, that is why I came here to ask.
Can you show a pic of that? By any chance, is the target pin yellow?
Like, I said, I probably haven’t set it up correctly, but I would like to replace the connected CastTo node with the above Interface node
Right. You have the wrong version of the BPI call.
Right click and search again, there are several. You need the one with has the envelope on it, which is a generic call to an actor.
The one with the yellow pin, is just a call to THIS actor and assumes it implements the interface.
Okay, so I figured it out. The out pin was using the wrong type. I changed it and now it connects. Making a child of the main Ai also shares the task, and so tick one problem down. 99 to go thanks
Ok, good
But if you want to use BPIs, surely you want the StartPatrol to be an interface call?
The blueprint should be a black box. You shouldn’t know about any internals.
One problem at a time. The first is to get it up and running, then balance the numbers, then next is to clean it up and make it look pretty and efficient.
When I am more seasoned and know what I need and how to do it. I will have it more clean, but in the meantime, meh it works.