Now that we have the majority of the Inventory working I wanted to jump into our hazards logic. The point of hazards in Max Proof is to basically have items that are dangerous become obstacles for Max when he ventures in the level. Upon stumbling on a hazard, points will be deducted. When we thought about creating hazards for Max Proof we wanted to make this as dynamic as possible. Having four years experience with Unreal Engine 3, I know the hassle you would have to go through to create logic for each individual item that does the same thing. Fortunately for Unreal Engine 4 they have class blueprints. So if I wanted to create a door that opens and closes, I can do it once and drop the blueprint as many times as I want in the level and the logic will remain. So when considering this how can we have a dynamic class that keeps consistency of the same logic? We can definitely do interfaces. In fact interfaces would be perfect for situations like this. Now having said that, we actually went a different route. My goal for this was to have one class that does it all. Thankfully in Unreal Engine 4 they introduce Construction Scripts.
In a Construction Script, you have the freedom to create logic that will run while in the editor. So what we did was create a generic item blueprint. In this Item blueprint we wanted to throw it in the level and then in the details panel be able to change the default mesh to whatever mesh we want it to be, change the material for that mesh, as well as the collision response for that mesh. So what we we're doing here is hey, all logic for the items are the same however, these items are different visually. Upon creating the item blueprint I two components; a static mesh and a trigger volume as a child of the mesh.
After doing that I went into it's construction script and created four variables. One of type Static mesh and I called it Custom Mesh. The other of type ECollisionResponse and I called it CollisionResponse. The next one of type ECollisionChannel and I called it CollisionChannel. The last was of type Material Instance and I called it Material. After creating all variables I went to each one and checked Editable. Now comes some logic for the construction script.
At the beginning when the construction script runs we have it where we set a static mesh, the target is CustomMesh. Then we set Collision Response to Channel. The Channel is CollisionChannel and and the response is CollisionResponse. After that we set Material of the mesh and the target is Material.
So if we were to jump into throwing an Item blueprint into the level, once clicking the item in the scenery we can see a few things added into the details panel. In the editor we can now change the item's static mesh, material, and as well as the collision response/channel. Now you may be wondering what's up with ItemObj and what does that mean. ItemObj actually identify s what object it is of that class. This will be discussed in a future blog where I get into creating hazards that can similarly to the inventory be able to pickup and drop into the world. Stay tune!
No comments:
Post a Comment