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...

No comments:

Post a Comment