And would I access that from the first
person character, or the object?
- an interface has a bunch of generic functions that do nothing
- actors with this interface have access to those functions; think new, yet undetermined behaviours & results
- actors can interpret what each function does to determine the result
- when the player interacts with an actor, it calls those generic functions of the interface - and it is the actor’s job to do something with that call
The player does not need to identify actors via casts, string comparison or booleans. The player interacts in a generic fashion with objects around them and it’s the actor’s job to identify itself to the player and act accordingly. The stuff that is important to the player is handled by the player. The stuff that is important to the actor is in the actor.
(I’ll keep posting as I find time between other tasks, the examples will be somewhat crude but stay tuned)
- aBaseInteractiveObject_BIO (BIO for short) is a base class with 3 children (that’s inheritance)
- any variables or components you want children to inherit are in the base
- here, the base class has a Static Mesh (simulating physics), a Text Render and a couple of variables
- each child actor can add their own unique stuff; for example, the BerryBush has 6 additional static meshes
- Handle_BIOs above is the Interface, seen below:
- it has 5 functions, some of which have inputs and / or outputs
- this way we can send data to and get data back from an actor who implements that function
This is the base class:
- it implements the above-mentioned interface
- it also means, that all children have it now and have access to the functions inside
- Above, I’ve implemented the Talk function in the base class
- it’s an Event because this function does not return a value (this is automatic)
- since this is implemented in the Base, all children will do it and show whatever string they were given
- children can still override it if necessary (perhaps there’s 1 object that you do not want to have a voice)
Here’s how the player interacts with the world:
- notice there’s no casting, no comparing of anything
- we just ask to execute the interface function in an actor
- even though only the base class Event Talks, all children mimic that behaviour but use their own MyText variable for that. There’s no script for this in any of the children.
Which looks like this:
And if you ask an actor with no interface to Talk (click the ground, wall, water, etc…), nothing happens. Which is great.