Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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.


Product Version: UE 4.8
more ▼

asked Jul 01 '15 at 03:31 PM in C++ Programming

avatar image

21 4 8 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jul 01 '15 at 04:14 PM

avatar image

349 21 18 35

avatar image MiguelDoherty Jul 01 '15 at 05:28 PM

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?

avatar image MiguelDoherty Jul 01 '15 at 06:59 PM

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
     /** 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;
     // Sets default values for this character's properties
     // 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;
avatar image MiguelDoherty Jul 01 '15 at 07:04 PM

Forget about it, it worked =)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question