Can't access C++ variable from Blueprint

Hey there,
I’m still trying to figure out how to use C++ with unreal and right now I’m trying to make a variable editable from the blueprint.

The thing is, I’m trying to add this variable in the Pawn class, here’s how I’m trying to create it:

/** If set to false (default) given pawn instance will never affect navigation generation. 
 *	Setting it to true will result in using regular AActor's navigation relevancy 
 *	calculation to check if this pawn instance should affect navigation generation
 *	Use SetCanAffectNavigationGeneration to change this value at runtime.
 *	Note that modifying this value at runtime will result in any navigation change only if runtime navigation generation is enabled. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Pawn)
uint32 bCanAffectNavigationGeneration : 1;

//The current target for this pawn
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Target)
APawn* bTarget;

Then, I compile the editor in Debug mode and try to create a Blueprint from the base class.
In the Blueprint Editor, I mark the “Show Inherited Variables” and I still can’t the bTarget variable, but I am able to see all other variables though.

Sorry if it should be easy, but I’m not an expert on C++ nor Unreal so… =P

I believe it has something to do with the fact that it’s not a basic type or something.

Thanks!

Assuming you have created a C++ project, if you modify the engine classes, it isn’t enough to compile your project editor, you’d have to recompile the UE4 project as well. Why not just add it to your project Character class (if indeed you have a C++ for your project). If it’s a bluprint project, you just add the variable to your blueprint.

Also, adding a bTarget to a Pawn break the abstraction. The idea is that not all pawns would necessarily have a target. Not even a Character might have a target. It would be more appropriate to extend the Pawn or Character and give it a target variable.

Forgive my ignorance here, but what exactly is the difference between the project editor vs the ue4 project?

I might be doing this the wrong way, but from what I was thinking, all Pawns in the project would have a Target, be it AI or Player, what would change was the way they interact with said target.

On a side node, I thought about making MyPawn(which would inherit maybe Pawn or Character) have the target variable and extending all my characters from it, but I actually want to reuse a lot of the Character class that comes with the project and I don’t believe it makes sense that an AI would extend from a Character class.

Edit: actually, I just looked at the Character class and what I just said makes no sense, AI should totally inherit from character class. I’ll probably be doing that approach! I believe that would count as an answer =P

Edit 2: That made me think in what cases I would use a Pawn instead of a Character?

Actually, that didn’t work =(

Here’s how my code for the ABaseCharacter looks like:

#pragma once

#include "GameFramework/Character.h"
#include "BaseCharacter.generated.h"

UCLASS(Blueprintable, BlueprintType)
class ALIENSVSSOLDIERS_API ABaseCharacter : public ACharacter
{
	GENERATED_BODY()
    
    /** Top down camera */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class UCameraComponent* TopDownCameraComponent;
    
    /** Camera boom positioning the camera above the character */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class USpringArmComponent* CameraBoom;


public:
	// Sets default values for this character's properties
	ABaseCharacter();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

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

    /** Returns TopDownCameraComponent subobject **/
    FORCEINLINE class UCameraComponent* GetTopDownCameraComponent() const { return TopDownCameraComponent; }
    /** Returns CameraBoom subobject **/
    FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }

    //The target for the current BaseCharacter
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Target)
    ABaseCharacter* Target;
	
};

Forget about it, it worked =)

If you are talking about a Blueprint derived from a C++ class, the “BlueprintReadWrite” enabled this for the Blueprint I derived from my C++ class:

From:

	UPROPERTY(EditAnywhere) bool ShowTarget = false;

to:

	UPROPERTY(EditAnywhere, BlueprintReadWrite) bool ShowTarget = false;