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.

1 comment: