A basic Blueprint Example
- I started with a First person Shooter.
- I deleted all of the extras from the scene.
- Lets build a box, an that
- Has a light that changes state when it is hit or run into.
- I created a new actor class blueprint called BP_Target
- Add a component
- Note I can move these in relationship to each other if I wish.
- Let's add two variables
- Both integers.
- hitCount and collisionCount
- I need to compile then I can set a default value.
- Note, I could also set a default value in the constructor script
- Let's select the Trigger and add an event handler.
- Start by just adding a print string to say "I was hit"
- Notice there are options (drop down menu in printString) that allow you to change some things.
- The Print String message fades fast, but note it is sent to a log.
- Notice under Window, Developer Tools you can turn on the print log.
- This is nice, you can see it a bit longer.
- Let's make it so I can turn the ligt on and off.
- We will do this with Set Visibiltiy
- But I will need a boolean to control this.
- So make a new boolean variable.
- And add a not node.
- Set Light On
- Wire this into the SetVisibility node too.
-
- Note, by clicking in the center of the get node I can turn "watch" on and off
- Select all of these nodes, right click and select "Collapse to Function"
- I had originally made this a macro but decided to promote this to a function. Please ignore macro pictures, it is a function
- Rename this function Toggle Light
- I connected the flow of control to the output.
- Let's add a function as well.
- This will increment a counter for us.
- Add a ++ node
- Click and select Collapse to Function
- Add a input parameter (Counter)
- Mark this as Pass By Reference
- Pipe Send this into the ++node
- ?
-
- Go back and add an On Actor Begin Overlap Event.
- Add a macro that prints the total hits and collisions.
-
- Add a function that does the same.
-
-
- Let's add a blue print to the level.
- Add a sphere and a collision sphere to the world.
- I renamed this LevelSphere.
- With the LevelSphere selected, edit the level blueprint.
- Select OnActorBeginOverlap
- Note, this is for the LevelSphere
- Get actor of class, note I want the BP_Target class.
- This is ok since I only have one.
- It would be a problem if I had multiples.
- From this Toggle Light
- Note, this is a member function of BP_Target
- You can call functions but not macros
- From This Increment Count
- Probably bad software design.
- Declare a world variable World Sphere Collisions
- Increment this.
- And print it out.
-
- I would like to build a subclass of the light.
- So click on BT_Target and select Create Child Blueprint Class
- I called this BP_MultiColorTarget
- I exposed the inherited member data so I could see Light On.
- I Only want to execute this code when the light is on so
-
- I built an array of light colors
-
- And an index
- And used those to set the new color for the light.
-
- Then incremented the index with wrap
-
-
- Overall, a bit of a mess but not too bad.
- And If I were to add functions ...