Towards a better Selector
- When we left our game last time, we had a BP_DestSwitch that required us to step on it
- I found it sort of annoying to have to go back and forth to be able to change multiple times.
- There has to be a better way.
- A look at events
- Events are things that happen.
- We have seen overlap begin, and by extension end
- We have seen hit.
- In fact, there are the basic ones listed here
- They provide some information on exactly what causes the event
- And what receives the event.
- When a given event "happen", the corresponding blueprint in the event graph is executed.
- These items are sometimes called callbacks in other environments.
- They are also called event handlers
- They say that an event can only be listed once in each object's event graph.
- This makes sense, as you can only do one thing when an event happens.
- Most events are straight forward
- With a collision you are given a pointer to the other actor
- But some are much more complex
- A hit event has 8 or more inputs.
- Apparently the main loop of the game is called a frame
- And the Event Tick event occurs every iteration.
- Looking about there appears to be a set of keyboard events.
- That gives me an idea. Let's build a class that responds to keypresses
- Just a collision box and a cube to show where it is.
- It needs a local variable active
- This will be true, when the player is "in" the box.
- Initialize it to be false.
- When the player has an overlap, set it to be true
- When the player is not longer overlapping set it to be false.
- Add a Event Keyboard, let's just pick B
-
- But when I run it, it doesn't Fire.
- It turns out, they have turned off input.
- But we can turn it on.
- There is an enable input node
- It takes a player controller.
- If we were in a multiplayer game, we would need to worry about this, but for now how about
-
- Probably should turn it off when we are not using it.
- You can do this with a Disable Input
- This eliminates the need for a "active" variable.
- Just for fun, I added a right mouse click as well.
-
- One last piece. Let's tie this to a transporter.
- Build a new variable of type BP_Transporter
- Expose this to the outside world.
- Now I want to be a bit careful.
- I don't want to call a function if this is not hooked to a transporter
- This would be a configuration problem.
- But just be careful.
- So I am going to check to make sure that it is not null
- In BP, this is the default value
-
- I am happy.
- Quick Aside, What buttons are used?
- We can't tell what buttons are used in other blueprints.
- But we can see what is mapped in the player controller.
- Edit Project settings.
- Select Input under Engine
- Explore the bindings.
- Create a new binding
-
- Access it in the first person character.
-
- Be careful with the event Any Key
- This takes keys away from the controller.
- On last note on events
- you can build custom events.
- There appears to be little difference between these and functions.