Devlog #3: Creating Puzzle Piece Tray


As a reminder for those who haven't read my previous devlogs, for this game I am following a UE4 jigsaw puzzle Blueprints tutorial and adapting it parts of it into C++ for practice. (Here's the tutorial below:)

Unreal Engine 4 Tutorial - Jigsaw Puzzle Part 3: Puzzle Screen

Expose on Spawn

Anyhow, at some point in the tutorial, the man edited the property of “expose on spawn” to true on some variables:


I looked online to see how to do the same thing in C++. I was able to learn about the “meta = (ExposeOnSpawn = "true")” flag of UPROPERTY, so I added it to the same variables the man in the tutorial did.

UPROPERTY(EditAnywhere, Category = "Puzzle", meta = (ExposeOnSpawn = "true"))
int NumberOfPieces;
UPROPERTY(EditAnywhere, Category = "Puzzle", meta = (ExposeOnSpawn = "true"))
FVector2D PuzzleCoordinate = FVector2D(2, 3);
UPROPERTY(EditAnywhere, Category = "Puzzle", meta = (ExposeOnSpawn = "true"))
UTexture* JigsawImage;

And this worked perfectly!!

Edit Anywhere

Somewhere in the process, I realized that I had slightly misunderstood the “EditAnywhere” flag of UPROPERTY. I thought it would allow me to edit it in the editor, on instances, and also edit it in blueprints.

However, “EditAnywhere” only allows you to edit the variable in the editor details panel and the default value in blueprints. It does not allow you to change its value in Blueprints at runtime. As such, I decided to use the property “BlueprintReadWrite” instead:

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "PyzzlePiece.generated.h"
// We make the class abstract, as we don't want to create
// instances of this, instead we want to create instances
// of our UMG Blueprint subclass.
UCLASS(Abstract)
class PUZZLEGAME_API UPyzzlePiece : public UUserWidget
{
GENERATED_BODY()
public:
/* Image Widget*/
UPROPERTY(BlueprintReadWrite, Category = "Puzzle", meta = (BindWidget))
class UImage* PuzzlePieceImageWidget;
UPROPERTY(BlueprintReadWrite, Category = "Puzzle")
class UMaterialInterface* PuzzleMaterial;
//not meant to be edited in editor, created at runtime
UPROPERTY(BlueprintReadWrite, Category = "Puzzle")
class UMaterialInstanceDynamic* DynamicMaterial;
UPROPERTY(BlueprintReadWrite, Category = "Puzzle", meta = (ExposeOnSpawn = "true"))
int NumberOfPieces;
UPROPERTY(BlueprintReadWrite, Category = "Puzzle", meta = (ExposeOnSpawn = "true"))
FVector2D PuzzleCoordinate = FVector2D(2, 3);
UPROPERTY(BlueprintReadWrite, Category = "Puzzle", meta = (ExposeOnSpawn = "true"))
UTexture* JigsawImage;
protected:
// Doing setup in the C++ constructor is not as useful as using NativeConstruct.
virtual void NativeConstruct() override;
};

Progress

Aaaand in the end, everything worked great! As you can see of the screenshot of the game below, the puzzle pieces were randomly generated on the left side of the screen! And they also spawned with the correct textures! Which means that the puzzle pieces do indeed only get textures at run-time, but appear blank in the widget blueprint editor.


Anyhow, here's some blueprint stuff I also did during this devlog:




That's all for this one! See you all next time!

Get Fyolai Puzzle Game

Leave a comment

Log in with itch.io to leave a comment.