Memory Game


The Memory Game sample is an example of a simple PC/mobile logic game. It is built only with Blueprints, with no additional code support.

Game Logic

The BP_LogicMem Blueprint is derived from the GameMode Class. This Blueprint is where the Default Pawn Class, the HUDClass, the Player Controller Class, the Spectator Class, and the GameReplicationInfo Class are set.

There are two Graphs in the BP_LogicMem Blueprint as well. EventGraph contains the initial setup of the game, the logic tests necessary for gameplay, and additional functionality such as moving back to the menu and displaying all the cards with the Hint button. FinishGame handles whether the player wins or loses, the number of stars awarded to the player, and the necessary end-of-game cleanup.

BP_Counter is called by BP_LogicMem using a Blueprint Interface to change the displayed number of moves, as well as to change the color of the text for the number of moves once there are fewer than 3 moves left.

Card Handling

The BP_DeckMem and BP_CardMem Blueprints are the primary Blueprints that manage how the cards are defined and laid out in the game. One instance of BP_DeckMem is placed in the game level, and it handles the spawning of BP_CardMem.

BP_DeckMem contains logic for creating and shuffling the card deck, spawning the cards, placing them on the board, and showing all the cards when the Hint button is pressed. The network for shuffling the deck is stored in the Shuffle function, which is called in the main EventGraph during new game preparation. After the deck is shuffled, BP_DeckMem spawns the cards, with different card placement based on the total number of cards. Every location on the board has an index: the CardDeckObjects array contains the BP_CardMem Blueprint that is at that index, while the CardDeckShuffled array holds information about the card type for that index. The Rotate event in BP_DeckMem flips all the cards when the Hint button is pressed.

BP_CardMem defines the picture on each card, defines the animations for placing, flipping, and removing the cards, and sets the ParticleEffects and sounds used when comparing cards.


Click Input

The BP_PlayerControllerMem Blueprint enables the Mouse Interface. Click events are enabled, while mouseover events are not. The Blueprints that contain click events are BP_MenuMem, BP_CardMem, and BP_Scoreboard. These Assign OnClicked Nodes are all activated from the ReceivedBeginPlay event, which will fire once the player begins the game.

Assign OnClicked Nodes create events tied to the delegate OnClicked. Delegates are ways for components of Blueprints to report on their state and trigger events based on their state changes. For example, once the Hint Button is clicked in the game, it reports that it has been clicked, and the Hint Button's OnClicked delegate triggers, activating a sequence of nodes that causes all the placed cards to flip over.

The variable BlockClick serves to prevent players from clicking on a card while it is flipped over or while it is in the process of flipping.

Frozen Camera

The BP_LogicMem Blueprint defines SpectatorPawn as the default Pawn Class. The Level Blueprint for the Memory Game places the SpectatorPawn at the PlayerStart, and the properties of the SpectatorPawn keeps the camera frozen in place throughout gameplay.

The Memory Game start menu is set up in the BP_MenuMem Blueprint using simple StaticMeshComponents. TextRenderComponents are used for the text and numbers, and a Timeline is used to move the menu out of the game window.
Using the menu, sets variables for the number of cards to use and whether or not to use a pair of black cards that will end the game if paired. These variables are sent to the BP_LogicMem and the BP_DeckMem Blueprints with the BPI_Communication Blueprint Interface.


The BP_Scoreboard Blueprint uses a combination of StaticMeshComponents and TextRenderComponents to create the summary menu that appears at the end of the game.