Cube Sample Application

This section explainins the UE4 Cube Sample application and how to use the Genvid Plugin and Module.

  1. Origin
  2. Content
  3. C++ Classes
  4. Blueprint Game Classes
  5. Blueprint Genvid Classes
  6. Blueprint Structures
  7. Assets
  8. How to run the Cube sample
  9. Genvid integration
  10. Instantiation

See Local Environment Usage for more information about running the Cube sample.

Note

Please make sure you use a version between 4.15.3 and 4.19.2 when running this sample.

Origin

The Cube sample uses the Unreal Engine 4 Basic Code template (New Project). The Cube sample is an adaptation from the Tutorial sample code. We added all available features to show all parts of the Genvid integration.

../../../_images/New_Project.png

Fig. 31 New Project

Content

The Cube sample displays 3 cubes named Athos, Porthos, and Aramis. These cubes rotate and move in various fixed directions. Upon reaching the extremity of the world, a sound plays and the cube moves to the opposite side of the world to continue its movement without interruption.

C++ Classes

  • Cube.cpp: This file implements the game module.
  • Cube.h: Header file of the game module.
  • ActorCube.cpp: Actor class which contains the matrix-transformation functions for the cubes.
  • ActorCube.h: Header file that declares the function to be callable in Blueprint.
  • Game.cpp: Class derived from UObject which contains the view-projection matrix of the player.
  • Game.h: Header file that declares the function to be callable in Blueprint.

Blueprint Game Classes

  • BP_Cube: Class used to show and manage a cube.
  • BP_Pawn: Class used as the default pawn.
  • BP_GameInstance: Class used to instantiate the Genvid Session Manager.
  • BP_GameMode: Class used to setup the game classes.
  • BP_GameState: Class used to receive Events and Commands from the client.
  • BP_PlayerController: Class used to send Events and Commands to the server.

Blueprint Genvid Classes

  • BP_GenvidSessionManager: Class used to manage the Genvid session.
  • BP_GenvidSession: Class used to set up the Genvid session.
  • BP_GenvidAudio: Class used to set up the Genvid audio-parameters.
  • BP_GenvidVideo: Class used to set up the Genvid video-parameters.
  • BP_GenvidStreams: Class used to set up the Genvid events.
  • BP_GenvidEvents: Class used to set up the Genvid events.
  • BP_GenvidCommands: Class used to set up the Genvid commands.

Blueprint Structures

  • BP_CubeData: Structure used to store the cube data.
  • BP_GameData: Structure used to store all cubes and the view-projection matrix.
  • BP_NameToColor: Structure used to store a color and its name.
  • BP_Popularity: Structure used to store the popularity of a cube name.
  • BP_PopularityData: Structure used to store all the cubes’ popularities.

Assets

  • MainMap : The game level map.
  • Colored_Steel : The material used by the cube.
  • galvanized_steel : The texture used by the material of the cube.
  • EdSplash.bmp : A splash screen used by the Unreal Editor.
  • Splash.bmp : A splash screen used by the Cube sample.

How to run the Cube sample

This guide assumes that your config file is properly set up with a working YouTube account (see Genvid Configuration) and that you can successfully run the Genvid services (see Local Environment Usage).

  1. Declare an environment variable named UE4ENGINEDIR that points to the Engine directory of your version of Unreal Engine 4. By default, it uses UE4ROOT/Engine, where UE4ROOT is the installation directory of Unreal Engine 4.
  2. Prepare the cube folder for building.
py cube.py prepare
This will copy the Genvid Plugin and Genvid Module under the
cube/app folder.
  1. Build the project (app and website).
py cube.py build

This generates the Visual Studio solution for the project and immediately tries to build it.

Note

If you encounter any issues when building the package:
  • Verify the uproject file is associated with Unreal Engine. Use the program UnrealVersionSelector in the Unreal Engine directory: Engine\Binaries\Win64.
  • If you have updated your engine version, try deleting the Intermediate directory in the Cube sample under samples\ue4\cube\app.
  1. Clean and load the project configuration.
genvid-sdk clean-config
genvid-sdk load-config-sdk
py cube.py load
  1. Start the project.
genvid-sdk start

Genvid integration

Create Genvid Blueprint Classes

There are seven classes that make it possible to integrate the Genvid SDK in your application directly through the Unreal Editor:

To do that, you need to create a Blueprint for each class.

../../../_images/UE4_Blueprint_Create_Genvid.png

Fig. 32 Genvid Blueprints

Once finished, you should have the following in your Content Browser.

../../../_images/Content_Browser_Blueprints_Genvid.png

Fig. 33 Content Browser (Genvid Blueprints)

Set up Blueprints

Once you create all the necessary Blueprints, you need to set them up.

BP_GenvidSessionManager

The BP_GenvidSessionManager class is a Data-Only Blueprint. You use it to select the Genvid Session.

In the Details tab:

  1. Select the GenvidVideo Blueprint you created for the Session Class you want to use.
  2. Select the Activate SDK option.

Note

We designed the Genvid Module to potentially handle multiple sessions in the future. For now, a GenvidSessionManager instance may only contain a single GenvidSession based on the current Genvid SDK design.

../../../_images/BP_GenvidSessionManager_Details1.png

Fig. 34 Genvid Session Manager

BP_GenvidSession

The BP_GenvidSession class is a Data-Only Blueprint. You use it to select the classes for the Video, Audio, Streams, Events, and Commands.

In the Details tab select the Blueprint you created for each class. (For example, select the Blueprint you created from GenvidVideo for Video Stream Class.)

../../../_images/BP_GenvidSession_Details1.png

Fig. 35 Genvid Session

BP_GenvidVideo

The BP_GenvidVideo class is a Data-Only Blueprint. You use it to set the parameters for a video stream:

  • Stream Name: Unique name for the video stream.
  • Video Mode: Video capture-mode. (Automatic or Texture)
  • Video Source: Video data-source. (Only if required by the Video Mode selected.)
../../../_images/BP_GenvidVideo_Details1.png

Fig. 36 Genvid Video

BP_GenvidAudio

The BP_GenvidAudio class is a Data-Only Blueprint. You use it to set the parameters for a audio stream:

../../../_images/BP_GenvidAudio_Details1.png

Fig. 37 Genvid Audio

BP_GenvidStreams

The BP_GenvidStreams class contains all required code to create and manage all the streams.

Use the GenvidStream structure to create a stream. Type Make GenvidStream in the All Possible Actions context menu to add it to the Event Graph.

../../../_images/BP_GenvidStreams_MakeGenvid_Menu1.png

Fig. 38 Make GenvidStream (Genvid Streams)

Once you have added the node, you can set the stream parameters:

  • Name: Unique name of the data stream.
  • Framerate: Rate to send the stream.
  • Stream (Tick): Event is called every frame. (Set by Framerate.)
  • Stream (Begin Play): Event is called one time when the stream is created.
  • Stream (Match Started): Event is called one time when the game starts.
  • Stream (Match Ended): Event is called one time when the game ends.
  • Stream (End Play): Event is called one time before the stream is destroyed.

Note

The Framerate property is only available for the event Stream (Tick).

Set the Framerate property to 0 to call the event only one time.

../../../_images/BP_GenvidStreams_MakeGenvidStream_PinOptions1.png

Fig. 39 GenvidStream Pin Options

For each stream event you select:

  1. Add a Custom Event. (Type Custom Event in the All Possible Actions context menu to add it to the Event Graph.)
  2. Add a node to the function you want to call from your Custom Event.
../../../_images/Blueprint_Construct_GenvidStreams1.gif

Fig. 40 Create Stream example

Caution

Stream Events are optional. If you select a stream event but you don’t link it to a custom event the Blueprint won’t compile. Either link it to a custom event or deselect it.

../../../_images/BP_GenvidStreams_AddCustomEvent_Menu.png

Fig. 41 Custom Event

After creating the Stream Event, add it to the Set Streams variable.

../../../_images/BP_GenvidStreams_SetStreams_Menu.png

Fig. 42 Set Streams Variable

The following images are examples of what fully-defined stream Blueprints look like. Your own Blueprints will vary, depending on how you decide to arrange and manage streams for your application.

../../../_images/BP_GenvidStreams_GameData.png

Fig. 43 GameData Stream

../../../_images/BP_GenvidStreams_Construct.png

Fig. 44 Genvid Streams Construction

BP_GenvidEvents

The class BP_GenvidEvents contains the code required to create and manage all Stream Events.

Use the GenvidEvent structure to create an event subscription. Type Make GenvidEvent in the All Possible Actions context menu to add it to the Event Graph.

../../../_images/BP_GenvidEvents_MakeGenvidEvent_Menu1.png

Fig. 45 Make GenvidEvent

Once you have added the node, you can set the event parameters:

  • Name: Unique name for the data stream.
  • Replicated: Call the delegate on client or server (Authoritative client/server networking model).
  • Delegate: Event triggered when the Genvid SDK receives an event.
../../../_images/BP_GenvidEvents_MakeGenvidEvent.png

Fig. 46 Genvid Event Parameters

From the Delegate parameter:

  1. Add a Custom Event. (Type Custom Event in the All Possible Actions context menu to add it to the Event Graph.)
  2. Select Add Custom Event... to add a node with predefined parameters.
../../../_images/BP_GenvidEvents_AddCustomEvent_Menu.png

Fig. 47 Custom Event

../../../_images/BP_GenvidEvents_AddCustomEvent.png

Fig. 48 Custom Event Node

Now add the new event to the Genvid Events variable.

  1. Type GenvidEvents Set Events in the All Possible Actions context menu.
  2. Select Set Events.
../../../_images/BP_GenvidEvents_SetEvents_Menu.png

Fig. 49 Events Variable

The following images are examples of what fully-defined event Blueprints look like. Your own Blueprints will vary, depending on how you decide to arrange and manage events for your application.

../../../_images/BP_GenvidEvents_Color.png

Fig. 50 Color Event

../../../_images/BP_GenvidEvents_Construct.png

Fig. 51 Genvid Events Construction

BP_GenvidCommands

The BP_GenvidCommands class contains the code required to create and manage commands.

Use the GenvidCommand structure to create a new command subscription. Type Make GenvidCommand in the All Possible Actions context menu to add it to the Event Graph.

../../../_images/BP_GenvidCommands_MakeGenvidCommand_Menu1.png

Fig. 52 Make GenvidCommand

Once you have added the node, you can set the command parameters:

  • Name: Unique name for the command.
  • Replicated: Call the delegate on client or server. (Authoritative client/server networking model.)
  • Delegate: Command triggered when the Genvid SDK receives a command.
../../../_images/BP_GenvidCommands_MakeGenvidCommand.png

Fig. 53 Genvid Command Parameters

From the Delegate parameter:

  1. Add a Custom Event. (Type Custom Event in the All Possible Actions context menu to add it to the Event Graph.)
  2. Select Add Custom Event... to add a node with predefined parameters.
../../../_images/BP_GenvidCommands_AddCustomEvent_Menu.png

Fig. 54 Custom Command

../../../_images/BP_GenvidCommands_AddCustomEvent.png

Fig. 55 Custom Command Node

Now add the new event to the Genvid Commands variable in GenvidCommands.

../../../_images/BP_GenvidCommands_SetCommands_Menu.png

Fig. 56 Commands Variable

The following images are examples of what fully-defined command Blueprints look like. Your own Blueprints will vary, depending on how you decide to arrange and manage commands for your application.

../../../_images/BP_GenvidCommands_Direction.png

Fig. 57 Direction Command

../../../_images/BP_GenvidCommands_Construct.png

Fig. 58 Genvid Commands Construction

UE4 Cube Sample Blueprints

The Blueprint class BP_Cube contains all required Game code.

The Blueprint class BP_GameInstance contains all required code to initialize and terminate a Genvid SessionManager.

../../../_images/GenvidSessionManager_Initialize_Terminate1.png

Fig. 59 GenvidSessionManager - Initialize/Terminate

It also contains all the code related to the Game Events and Game Commands.

Events:
  • ChangeColor
  • Cheer
  • Reset
Commands:
  • Direction
  • Speed
  • Reset

The Blueprint class BP_GameMode contains all the settings to use customized classes for AGameState and APlayerState based classes.

../../../_images/BP_GameMode.png

Fig. 60 GameMode

The Blueprint class BP_GameState contains all the required code to receive the Genvid Events and Commands.

../../../_images/BP_GameState.png

Fig. 61 GameState

The Blueprint class BP_PlayerController contains three components:

  • BP_GenvidStreams
  • BP_GenvidEvents
  • BP_GenvidCommands

This is necessary to follow the Genvid SDK Client/Server architecture. Take a look at Unreal Engine 4 Genvid Client/Server for more information.

../../../_images/BP_PlayerController.png

Fig. 62 PlayerController

Note

All data structures are automatically serialized in JSON when you submit game data to the server.

Instantiation

The Genvid Session automatically manages Audio/Video Capture initialization and finalization.

All Streams, Events, and Commands are Managed by the PlayerController.

A good place to instantiate the GenvidSessionManager is in a UGameInstance-based class. Call the Initialize() function when the application starts and Terminate() when the application stops.