Blueprint not seeing variable from native parent

Hello,

First I’m very new (just coming back from another engine)
I’m trying to use a native header file to store variables.
I have managed to reparent the blueprint to this c++ header.
Everything seems all on the up and up with the code.
However the blueprint is not letting me use the variable.
Also My copy of Visual studio 2019 wasn’t auto completing any unreal keywords, except Uproperty itself.
I would greatly appreciate any help!

Thanks!
–Joshua

************************************************Header file *********************************************
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “CoreMinimal.h”
#include “GameFramework/Character.h”
#include “CharacterData.generated.h”

UCLASS()
class BALLROLLER_API ACharacterData : public ACharacter
{
GENERATED_BODY()

public:
// Sets default values for this character’s properties
ACharacterData();

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

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

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

UPROPERTY(Editanywhere)
int gamescore;

};

**********************************************CPP file *****************************************************************

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

#include “CharacterData.h”

// Sets default values
ACharacterData::ACharacterData()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void ACharacterData::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void ACharacterData::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void ACharacterData::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);

}

Header file * // Fill out your copyright notice in the Description page of Project Settings.

pragma once

include “CoreMinimal.h”

include “GameFramework/Character.h” #include “CharacterData.generated.h”

UCLASS() class BALLROLLER_API ACharacterData : public ACharacter { GENERATED_BODY()

public: // Sets default values for this character’s properties ACharacterData();

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

public:
// Called every frame virtual void Tick(float DeltaTime) override;

// Called to bind functionality to input

virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

UPROPERTY(Editanywhere)

int gamescore;

};

CPP file ***

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

include “CharacterData.h”

// Sets default values ACharacterData::ACharacterData() { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it. PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned void ACharacterData::BeginPlay() { Super::BeginPlay();

}

// Called every frame void ACharacterData::Tick(float DeltaTime) { Super::Tick(DeltaTime);

}

// Called to bind functionality to input void ACharacterData::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent);

}

I can’t help if it is a C++ problem, but did you try clicking the little eye icon near the top of the “My Blueprint” tab? I believe it controls what all you see in the tab. Assuming you coded it correctly, maybe it is just hiding parent variables atm?

C++ Variables, when only “EditAnywhere” is specified, will only appear (and be editable) through the Details Panel (either instance or default i.e. anywhere).

The variables should not appear in the variables list in blueprints with these settings.You have to add either BlueprintReadOnly, or BlueprintReadWrite to the UPROPERTY. So it would look like this:

UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 GameScore;

Also, make sure to be using “int32” instead of “int”.

I forgot to add blueprintable macro to the c++ header file.

I’ll try that when I get home. The blueprint does link to the soucecode as its parent.

Thank you for the reply though!

Yes just parent variables. I wanted to eliminate casting to other blueprints to give an increase in performance

This seems like a terrible bit of trouble, I’m running into issues still.
how much of a performance hit would I get if I just had every object that needed to access the player’s health be a child blueprint of the player blueprint?
So it would still inherit the values but from a blueprint containing the variable instead of a c++ header file containing the variable?

No need to do that. You just need to have the following:

  1. C++ Character Class where you add all your core logic (and that has the UPROPERTY mentioned to access these variables)

  2. Blueprint Character Class that inherits from this C++ Character Class. No need to have all your blueprints inherit the Character class.

If you think you have done that, can you screenshot both the C++ class in the Unreal Editor and the Blueprint class showing that it inherits that C++ class?
Also it wouldn’t hurt if you screenshot the Header file of your C++ class

I’ll be able to attempt this tonight. I’m about to head out to work.

So I tried it again with a new project (this project is jsut for testing coding)
in unreal 4.25

I will be attaching screenshots and posting the code.

alt text

Header File

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

#pragma once

#include “CoreMinimal.h”
#include “GameFramework/Character.h”
#include “CPPtest.generated.h”

UCLASS(Blueprintable)
class ROLLABALLA2020_API ACPPtest : public ACharacter
{
GENERATED_BODY()

public:
// Sets default values for this character’s properties
ACPPtest();

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

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

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

UPROPERTY(BlueprintReadWrite, EditAnywhere) int32 score;

};

CPP File

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

#include “CPPtest.h”

// Sets default values
ACPPtest::ACPPtest()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
//PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void ACPPtest::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void ACPPtest::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void ACPPtest::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);

}

First, you don’t need to add “Blueprintable”. It’s not necessary. You can create a child blueprint without it. Second, make sure you have compiled the project. Third, right click on the graph and search for “score”.
If you still have issues, send me a link to download the project and I will tell you where the problem is.

I’ll send it after work tomorrow (hopefully I can fit it on my dropbox)

Did you want the entire project or just the visual studio files?

The entire project would be better.

Thanks again for your help!

I’m experimenting with online storage.
Please let me know if this works!

There’s absolutely no problem with your project. Just make sure to Compile the project and do the following:

https://imgur.com/a/QSVc7LZ

(note, i didn’t change any code at all. Compiled and checked right away)