Instance vs Default

Hi There!!

In this lecture, we discuss the visibility and editability of our variables.

VS Code-

Header file-

// Fill out your copyright notice on the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "BasePawn.generated.h"

UCLASS()
class TOONTANKS_API ABasePawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	ABasePawn();

	UPROPERTY(VisibleAnywhere)
	int32 VisibleAnywhereInt = 12;

	UPROPERTY(EditAnywhere)
	int32 EditAnywhereInt = 22;

	UPROPERTY(VisibleInstanceOnly)
	int32 VisibleInstanceOnlyInt = 82;

	UPROPERTY(EditAnywhere)
	int32 Damage = 41;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

private:
	UPROPERTY()
	class UCapsuleComponent* CapsuleComp;
	UPROPERTY()
	UStaticMeshComponent* BaseMesh;
	UPROPERTY()
	UStaticMeshComponent* TurretMesh;
	UPROPERTY()
	USceneComponent* ProjectileSpawnPoint;
public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};

In my first public section, you can see I’ve declared few variables. In the UPROPERTY() macro, you’ll see some unfamiliar arguments passed in the parentheses. Don’t worry I got you.

VisibleAnywhere - Makes the variable visible both in blueprints and the editor.

Blueprints -

Editor -

EditAnywhere - This allows us to edit the variables both in blueprints and the editor.

Blueprints -

Editor -

VisibleInstanceOnly - Makes the variable visible, but not editable, in the editor.

Blueprints -

(There is no VisibleInstanceOnlyInt variable here.)

Editor-

And I’m really sorry for the terrible outlining.

The damage variable I created was just part of the challenge, and it’s the same as the EditAnywhere argument.

Previous Toon Tanks post: Deriving Blueprint Classes

Thanks for reading,
Good Bye!!

2 Likes

Haha yes you do got me :sunglasses:

1 Like

I’m happy I did :sweat_smile: :sweat_smile:

1 Like

You da best :pleading_face:

1 Like

Thank you! Your replies really motivate me to go ahead :grin: :grin:.