Sunday, August 28, 2016

C++ Object Construction Working

C++ Object Construction: It Works!


I can now create static meshes via code!

This was a lot more annoying that it should have been. Every example on the web was wrong because Unreal has altered the API.

My function to build an object is simply this:
SpawnBlock(FString MeshLocation, FVector Location, FRotator Rotation, FVector Scale)

That is how it should be. I will default the rotation and scale so you only have to provide a mesh location and X/Y/Z coordinates for it.

I fine tuned my performance analysis:
you can have 11x11 non shadow casting actors in your vision without stutter (at least on my machine). I built an 11x11 matrix of cubes in front and behind me and neither produced stutter. 12x12 objects in front of my started causing slight jumps. My prior test was 19x19 with me at the center of the cubes. That is likely similar numbers, just a different way of thinking about it...

Getting object construction in place is all the wiggle room I needed to get started producing environments.


I played with the functionality to randomly pick between a blue and texture material:


This is all with one AActor class.

They make it REALLY hard to do this because:
1. The actor is created from a factory
2. You can only find meshs and materials in the constructor
3. You can't pass anything custom into the constructor.

It is a real suck fest.

My only way around this is to either:
1. create an object name that is unique and communicates mesh and material to pick
2. communicate via static variables

static variables will be my current approach but that is fragile. If the construction of these actors ever becomes multi-threaded, it will break.

Saturday, August 27, 2016

Unreal Performance Testing with the Vive

Unreal Vive Performance Testing


I've been doing some performance testing to see how to increase the number of objects on the screen.

Here is what I found:
1. Turning off casting shadows has a huge impact on performance.
2. Objects with 2 textures and few triangles (12) hurt performance more than objects with 1 texture and more triangles (156). I'm glad I learned that now. Multi-texture objects are out!
3. Distance without LOD has no effect on performance. To be expected but good to know.
4. Scale has no impact on performance
5. Static vs moveable has no impact
6. Turning on the tick for an object has no impact
7. scaling/rotating/moving an object has a HUGE impact on performance. Very very bad.
8. A material with color versus an image has no impact on performance. This was surprising to me.
9. Executing code each tick without affecting the object had no impact on performance.
10. The sky box had no impact on performance.

With no shadow casting, 1 texture UV mapped on the object and no movement, I was able to put 19x19x19 (6859) objects on the screen without a stutter.

This was a huge increase from before.

Now... I can't just be adding objects without shadow casting but I will try to avoid it when at all possible.

I also did testing of what felt visibly acceptable for the number of generated landscape regions/squares. I found that 10x10 felt very reasonable. I will allow players to customize that area so we'll see what works as things progress.

This scene was produced from my automatic object generation blueprint. I just tweaked the scale and only allowed one vertical row of objects to be created.


Next steps:
1. convert the code to pure c++
2. start adding shadow casting objects
3. look into using landscape mesh grouping to allow more of the same object on the screen at one time.

Update:
Since everything in my game will be built on the fly, I needed to figure out where exactly that should happen. I had a false start by creating a blueprint function and hooked it into my level start. That works but it isn't the correct spot for it. The correct place appears to be "Game Mode". I create a custom game mode, tell the world to use it and this acts as the "overseer" to landscape, item and player spawning/destruction.

Here is the documentation for how the Unreal Engine works. I hate spending all my time reading but this is pretty important stuff:
https://docs.unrealengine.com/latest/INT/Gameplay/Framework/index.html

Friday, August 26, 2016

A little blueprint demo

I put together a little demo using blueprint and c++.

I created an actor that hovered and spun in c++

HEADER:

#pragma once

#include "GameFramework/Actor.h"
#include "FloatingActor.generated.h"

DECLARE_LOG_CATEGORY_EXTERN(MyLog, Log, All);

UCLASS()
class SIDE_STEP_API AFloatingActor : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor's properties
AFloatingActor();

// Called when the game starts or when spawned
virtual void BeginPlay() override;

// Called every frame
virtual void Tick( float DeltaSeconds ) override;

float RunningTime;

};

CPP FILE:

#include "side_step.h"
#include "FloatingActor.h"

DEFINE_LOG_CATEGORY(MyLog);

// Sets default values
AFloatingActor::AFloatingActor() {
  // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

UE_LOG(MyLog, Log, TEXT("Floating actor constructed"));

}

// Called when the game starts or when spawned
void AFloatingActor::BeginPlay() {
Super::BeginPlay();

}

// Called every frame
void AFloatingActor::Tick( float DeltaTime ) {
Super::Tick( DeltaTime );

FVector NewLocation = GetActorLocation();
float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
NewLocation.Z += DeltaHeight * 50.0f;       //Scale our height by a factor of 20
RunningTime += DeltaTime;
SetActorLocation(NewLocation);

FRotator NewRotation = GetActorRotation();
NewRotation.Pitch = (RunningTime + DeltaTime) * 20.0f;
NewRotation.Roll = (RunningTime + DeltaTime) * 20.0f;
NewRotation.Yaw = (RunningTime + DeltaTime) * 20.0f;
SetActorRotation(NewRotation);

// UE_LOG(MyLog, Log, TEXT("Delta Height for float: %f"), DeltaHeight);
}

I then used the level blueprint code to spawn this actor a bunch of times.

I created variables to control the number of actors spawned and their distance.
> I see that Unreal blew up and lost the distance variable... sigh...



This is the result:

It didn't take much experimentation to discover the number actors I can put on the screen is pretty pathetic. 6x6x6 (216) on my beastly machine. If I went to 7x7x7 it choked in certain directions.

That is a frighteningly small amount of cubes on the screen at once before stutter sets in.

I really have my work cut out for me...

c++ and Unreal

c++ and Unreal


This has been taking a lot longer than I expected.

First I took a break and played No Mans Sky. I sunk a week and a half into that game. Then I found out what the ending was. There is no ending! That was the last straw. I went back and watched early trailers, footage and interviews with Sean Murray. That guy is a big fat liar. It is crazy. When someone would ask him if something was in the game he would always say yes. He would even say things that were clearly not in the game. I played the PS4 version. I has also preordered the limited edition for PC from 8-bit. I am unable to return it even though they haven't shipped it to me!


Anyway.

I promise you this. I will never misrepresent anything in my game development. I will tell you exactly where I stand. If you can't start from an honest position, you've got nowhere to go. Vaporware is one thing, but telling people something is there when it clearly isn't is disrespectful.

OK, so I digress... why has it been taking so long to get started...

First I needed to install visual studio and brush up on c++.

Then I watched a horrible youtube video series on Unreal and c++ wasting hours of my time. I did learn how to output to the log from with c++ and monitor the unreal log, so I guess that is something...

Now I am watching a series that is much more informative and practical:
https://www.youtube.com/watch?v=zEcNn4gWas0

This is how it goes with any development. There is an incubation period where you are learning. Once I push through this I can start implementing my vision.

The ironic thing is I have already psuedo coded the classes for my world generation. I just need to implement them in c++, hook it into unreal, see where the performance bottlenecks are and I'll be off an running. So hopefully in the next few weeks I will see some results for all my slogging through retraining in blender, Unreal and c++.

Friday, August 12, 2016

Unreal C++

This weekend's objective:

Create 2 c++ classes and expose them to blueprint. This may turn out to be nastier than I expect since I need to brush off my c++ coding skills and install a c++ editor.

TMap wrapper
It boggles my mind that Unreal doesn't support maps/hashes natively. Any language worth its salt has this.

In case you don't program much, these are the core containers that need supported:
array/list (a list of objects in order. A list is usually a wrapper around an array automatically managing size)
map/hash (using a key you can get an object back)
set (unique container of objects. I can limp along without this but it is handy)

Environment maintenance
I will be procedurally constructing everything. I need a class that will manage this that I can expose to blueprints. Example: As the player moves, this class will update the environment. Environment construction relies on a seed for randomly generating everything. It also relies on a variety of performance settings. This will not only control object/landscape/actor spawn/de-spawn but perimeter effects such as fog. It will have a variety of other tasks I will implement later as things progress

This is pretty close to where I want to begin with environment creation:

I will start with something brain-dead simple like this:





When I have something working I will post a screen shot of it.

Wednesday, August 10, 2016

No Man's Sky



I haven't played the game yet but I've been reading reactions. This is very important because I am also creating a procedural world. I will be posting reactions that provide specific insights.

Here is one:

https://www.reddit.com/r/gaming/comments/4x1ua9/just_remember_this_piece_of_common_sense/d6bt69y

Been playing this game for a while now, and even though it's too early to give a final opinion on this game, so far it's been underwhelming to say the least. I don't personally care about multiplayer as much as I do about just how empty this game is, and how quickly you end up recognizing the patterns behind the algorithm that generates these terrains, plants and animals. Once you do, all of the interest in exploring new planets quickly fades as you realize that the next animal will simply be a new permutations of parts you've already seen, or that the next planet will be a combination of geologic and plant features you've already seen but just shuffled up differently. If you have a few dozen body designs set for each section of the body, you can get an insane amount of permutations (just how you can shuffle a 52 card deck into an absurd number of variations), but ultimately they're all the same.
The survival mechanics are horribly unfun. I'm not sure many people seem to enjoy mineral collection, especially due to a really small inventory size. It mostly consists of scanning and following icons, and is incredibly repetitive and not very rewarding. Combat is also really unsatisfying, with enemies that don't react to getting hit and no real threat outside of space (where the main weapon is a lock-on laser). The exploration controls with the ship are pretty decent and it's fun to fly around while listening to the excellent atmospheric music, but wears out its welcome fast because there's not much exciting hidden content. The monoliths you find don't give much, alien outposts are not exciting.
There are a few things that this game needs badly:
  1. Implement bases, storage, and furniture. This needs to be done almost immediately. I want to be able to set up base camps on planets, forge for resources, and store extra stuff.
  2. Add unique non-generated content that add some sort of story or quest with specific details about a past civilization, more than the generic monoliths. The bottom line is this: human-made content with some sort of narrative will always, always have more thought put into it than content spit out haphazardly by an algorithm.
  3. Bases need special atmosphere bubbles, so you cant start farms and bring different animals from different planets there. This should include plants, let's grow plants from other planets on new planets, or seed dead worlds.
  4. I want to be able to take animals to them and move them from planet to planet. Add cargo ships at least.
  5. Fix the map so we can see the names of the systems you've already been to.
  6. Fix the inventory so its not a nightmare to manage. You spend most of the time in this game mining and grinding for materials, at least make this part seamless.
  7. Add some variation to the animal behavior. Simply varying the colors and meshes isn't enough, they all do similar pathfinding and don't attack and interact with each other. There should be an entire ecosystem of realistic behaviors, with full life cycles and possibly some mechanics that we can study these and earn some sort of reward. Right now "taming" them essentially means they poop out resources.
Those need to be done like, IMMEDIATELY. I can respect the sheer ambition of this title, but the fact that this was developed by a team of like 15 people also shows throughout. This game is fucking empty.

Sunday, August 7, 2016

Choosing a direction

There is so much to learn it can be overwhelming to know where to go next, The myriad of directions leaves you sometimes going in none. Option overload...

Should I polish my blender skills?
Should I continue to study blueprints?
Should I practice importing meshes and textures?
Should I build a sample scene?
Should I write some C++ and see how it hooks into the engine?
Should I build some materials?

The list goes on and on...

I generally know what I need to do but I am afraid if I try to hit the ground running with too little tool knowledge I will handicap myself by doing something the wrong/hard way.

I'm sure other game developers feel this way too. I could spend a year just learning tools inside and out and that would leave me without any progress on my game.

I think I am going to spend the day brushing up on my blender skills. I've done a ton of blender work in the past but I've noticed my second nature keystrokes have gotten rusty. I need that 3D modelling back in working order. Building meshes quickly and getting them into Unreal is very important for a 1 man shop like myself.


Saturday, August 6, 2016

Multiple Texture UV Mapping in Blender for Unreal 4

Multiple Texture UV Mapping in Blender for Unreal 4

That is quite a mouth full for a title but it is important for creating a large and efficient environment.

The current trend with texture mapping is to create 1 material per object. This allows you to do some very cool things with tools like Substance Designer. If you have a lot of objects, that is going to be a lot of textures in memory.

I am building a game that will have expansive landscapes / scenes. I need to be very performance conscious from the outset. This includes reusing textures and mapping multiple textures onto one object when necessary. This will allow me to have fewer textures in memory.

I am a bit rusty with Blender but it is coming back to me.

Here is a simple example of creating a cube with collision and 2 texture UV mappings. I can view the object in blender with the textures and in Unreal with the textures once imported.


STEP 1: Setting up Blender (One time setup)


Unreal has a different object scale than blender. We need to adjust blender to build objects to Unreal's scale. Set scale to 0.010


We also need change the view clip so it doesn't freak out with unusually large scaled objects:


Make sure the end value is 500m not 500mm.

I scaled up the default cube so it looked normal size.


STEP 2: Collision Mesh


I copied the cube, slightly enlarged the copy, renamed the copy to UCX_{object name}_{number}. I also changed the UCX to be wireframe. Note: You can have as many collision meshes for an object. Each collision mesh must start with UCX_{object name}.



Step 3: Add Materials


I used to do UV mapping without adding materials in blender. This worked for UDK. This does not work for Unreal...

Select your object and add a material:


With the material selected, click on the texture tab and load the texture:


Repeat this process for the second material/texture.

Step 4: UV Mapping


Before we do UV mapping, lets make sure the object will display the textures from the UV editor in the 3D View:


Now we need to UV map onto the material and simultaneously a texture with the UV editor.

Lets split the 3D view to include the "UV/Image Editor":


Select the cube, go into edit mode, be in face select mode, select 3 of the 6 faces (3 for 1 texture and 3 eventually for the other), press U for unwrap and select "Smart UV Project". Now open the texture in the UV mapping for the 3 sides:


Now to complete the mapping we need to assign it to the material:


Repeat this for the other 3 faces. In the end you will have an object that looks like the one in the 3D view above.

Step 5: Import into Unreal


Now export this to FBX. Don't adjust any settings.

Open Unreal and import the FBX. If everything went well, you will have a properly scaled object with collision and 2 texture materials mapped to it:


This will drop right into the level and works.

The end goal is to not load the textures/materials into Unreal since they should already exist. But for a quick Proof of Concept, this worked surprisingly well.

My only complaint is I have to make sure I have the textures selected in the UV editor or it won't display correctly in the 3D View. It will render, but that isn't very helpful when building/adjust the object.

Friday, August 5, 2016

Unreal Blueprint Research

Unreal Blueprint Work

I am starting to dig into blueprint. I do software development in Ruby and have done c++ and Java among other languages so programming doesn't worry me. 

I am trying to wrap my head around 3D specific concerns such as vectors, rotators, transforms, lerps, etc.

I created this cheat sheet I will tape to the side of my monitor for reference until I have the variable colors and types down cold:


I watched a few quickie blueprint videos from Unreal on creating a hovering object and slowing time until a character moved. Those were amazingly easy. 

I'm building a text file with a list of important functions as I run across them in tutorials. I will post the contents of it here. I will update a number in parens when I encounter the function multiple times. This will help me gauge the usefulness of the function.

========================================================================
UNREAL BLUEPRINT NOTES
========================================================================

---------------------------------------------------------------------------------------------------
Variable Types
---------------------------------------------------------------------------------------------------

https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Variables/

Boolean (RED)

Integer (CYAN)

Float (GREEN)

String (MAGENTA)

Text (PINK)
 localization?

Vector (GOLD)
 3 floats (traditionally for XYZ or RGB)
 https://www.youtube.com/watch?v=WHGkLLIlz78

Rotator (PURPLE)
 group of numbers defining rotation in 3D space
 Ususally just interested in Pitch and Yaw

Transform (ORANGE)
 Cobines 3 attributes of an object:
 translatioon (3D location)
 rotation
 scale

Object (BLUE)

---------------------------------------------------------------------------------------------------
Terms
---------------------------------------------------------------------------------------------------

Primitive Component
> any component we can apply physics to (ex: static mesh)

---------------------------------------------------------------------------------------------------
Notes
---------------------------------------------------------------------------------------------------

To make an object be able to move, must sure you change "Mobility" to Movable

You can drag blueprints onto objects in the component list to associate them
> example was a hover blueprint. Dragged onto a movable object, it made it hover
> scene component blueprints have this ability. Maybe others. Unsure

---------------------------------------------------------------------------------------------------
Functions
---------------------------------------------------------------------------------------------------

DEBUGGING .........................................................................................

Draw Debug Line
 draws a line between 2 points.

Line Trace By Channel
 Draws and erases a line every frame

Print String (USEFUL FOR DEBUGGING)
 Prints a string on the screen (great for debugging)

Get Display Name
 Lets you get the name of an actor
 Can be used to show the name of an actor you have hit with a vector
 This does not appear to work on static meshes

CONSOLE ...........................................................................................

Execute Console Command
 Example: slomo

EVENTS ............................................................................................

Event Begin Play
 When game play starts

Event Tick (3)
 Fired at every frame

ACTOR EVENTS ......................................................................................

Event Actor Begin Overlap
 When another actor overlaps this actor
 You can cast this to ThirdPersonCharacter

Event Initialize Component

VECTOR MANIPULATION ...............................................................................

Break Vector
 Allows you to manipulate each component (X,Y,Z)

Convert Vector into Linear Color
 Covert RGB into single value for "set light color"

Get Vector Length
 Get the magnitude/length of a vector (returns a float)
 Can be used to convert a vector into a useful float

Vector + Vector
 Adds 2 vectors

UNCATEGORIZED .....................................................................................

Break Hit Result
 Breaks out the result of a vector hitting an object
 Can be used to break out the result of "Line Trace By Channel"

Build String (Float)
 convert float to string with a prefix.
 Can be fed into "execute console command"

Get Actor Location
 Get the location of the actor

Get Control Rotation
 Rotation of the object

Get Forward Vector
 Can be used to convert a rotation into a vector
 > The length of the vector is 1 (XYZ values are decimals less than 1)
 > This produces a normalized/direction/unit vector (it always has a length/magnitude of 1)

Get Owner
 Actor a blueprint has been attached to
 > useful for doing work against the owner and inspecting it

Get Velocity
 Get velocity of object (vector)

Launch Character
 You can add a velocity to an actor

Map Range
 Convert 1 range of numbers proportionally into a different range
 Useful for coverting a large range to 0 thru 1 or vice-versa

Random Unit Vector
 creates a random vector (3 variable array)

Set Light Color
 Change the color of a target light

Set Timer by Event
 Allows you to create a looping timer that can trigger an event

Monday, August 1, 2016

Distance and VR

Distance and VR.



I played 15 minutes of "Call of the Starseed" yesterday for the first time.

I am immune to immersion in VR. I've spent way too many hours within VR for it to emotionally affect me. Because of this I immediately look for drawbacks in design.

I think this title, along with others, suffers from scale. I can see how far out the stars are and I feel enclosed within a large bubble. This may be done for performance reasons but it makes me feel like I am not in a world but on a stage.

Having an unending horizon is very important to me and I will be making it a high priority. I would rather the edge of perception be clouded/misty than give the feel that I am in a sphere.

One of my favorite games that deals with horizon and is amazing efficient is Blades of Brim by Sybo games.


I don't know how they do it but that game is amazing on an ipad. It even has portals! It is damn slick and an inspiration for me.