x

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. 

Changes to C++ not reflected in editor/BluePrint

Hi Everyone,

Im new to the unreal engine but have a background in software development as my day job. Im following one of thee unreal tutorials on character creation and movement. However I have come across an issue that I cant resolve. I created my character in a C++ class and then created a blueprint from it, the blueprint is now being used as my default pawn class in project settings. I have a static mesh for my character and have in C++ created a first person camera component and attached it to the player capsule, this is working and I can see the camera when opening the blueprint. However after I change the value in C++ for the camera location (from 50.0f to 100.0f for example) and then hit compile, this change is not reflected in the editor. Also im calling GetMesh()->SetOwnerNoSee(true); in the character constructor, which I thought should stop me seeing it in first person but yet it persists in the editor. Any ideas would be greatly appreciated, code below for reference.

TestCharacter.h

 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Character.h"
 #include "Camera/CameraComponent.h"
 #include "TestCharacter.generated.h"
 
 UCLASS()
 class LEARNING_API ATestCharacter : public ACharacter
 {
     GENERATED_BODY()
 
 public:
     // Sets default values for this character's properties
     ATestCharacter();
 
 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;
 
     // Handles input for moving forward and backward.
     UFUNCTION()
         void MoveForward(float Value);
 
     // Handles input for moving right and left.
     UFUNCTION()
         void MoveRight(float Value);
 
     UFUNCTION()
         void StartJump();
 
     UFUNCTION()
         void StopJump();
 
     UPROPERTY()
         UCameraComponent* FPSCameraComponent;
 
 };

TestCharacter.cpp

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "TestCharacter.h"
 #include "Components/CapsuleComponent.h"
 #include "Engine/Engine.h"
 #include "Components/StaticMeshComponent.h"
 
 
 // Sets default values
 ATestCharacter::ATestCharacter()
 {
      // 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;
 
     //Create First Person Camera Component
     FPSCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
 
     //Now attach the camera to the player capsule/sphere
     FPSCameraComponent->SetupAttachment(GetCapsuleComponent());
 
     // Position the camera slightly above the eyes.
     FPSCameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f + BaseEyeHeight));
     
     // Allow the pawn to control camera rotation.
     FPSCameraComponent->bUsePawnControlRotation = true;
 
     GetMesh()->SetOwnerNoSee(true);
 
 }
 
 // Called when the game starts or when spawned
 void ATestCharacter::BeginPlay()
 {
     Super::BeginPlay();
 
     if (GEngine) {
         GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, TEXT("Test"));
     }
     
 }
 
 // Called every frame
 void ATestCharacter::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
 }
 
 // Called to bind functionality to input
 void ATestCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
 {
     Super::SetupPlayerInputComponent(PlayerInputComponent);
 
     //Player Axis Movements
     PlayerInputComponent->BindAxis("MoveForward", this, &ATestCharacter::MoveForward);
     PlayerInputComponent->BindAxis("MoveRight", this, &ATestCharacter::MoveRight);
     PlayerInputComponent->BindAxis("LookUp", this, &ATestCharacter::AddControllerPitchInput);
     PlayerInputComponent->BindAxis("Turn", this, &ATestCharacter::AddControllerYawInput);
 
     //Player Action Control Bindings
 
     PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ATestCharacter::StartJump);
     PlayerInputComponent->BindAction("Jump", IE_Released, this, &ATestCharacter::StopJump);
 
     
 
 }
 
 void ATestCharacter::MoveForward(float Value)
 {
     // Find out which way is "forward" and record that the player wants to move that way.
     FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
     AddMovementInput(Direction, Value);
 }
 
 void ATestCharacter::MoveRight(float Value)
 {
     FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
     AddMovementInput(Direction, Value);
 }
 
 void ATestCharacter::StartJump()
 {
     bPressedJump = true;
 }
 
 void ATestCharacter::StopJump()
 {
     bPressedJump = false;
 }
 
 

Product Version: UE 4.18
Tags:
more ▼

asked Mar 03 '18 at 10:45 PM in C++ Programming

avatar image

Dannyboi8181
1

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

1 answer: sort voted first

Hey!

If you moved your camera in blueprint (editor), that change will be saved. No matter if you change the value in constructor..

Technically reflected variables / values is only default valuse and can be modified in blueprint.. Unreal keep modified values everytime... if you reset transformation to default (yellow arrow near of the transform) should be go back to your c++ value..

But just mentioning this.. maybe you just moved the camera.. If not possible error can be FPSCameraComponent->bUsePawnControlRotation = true; as i remember this reset the camera location maybe... im not sure... add a springarm component if you wanna use pawnrotation and attach camera to springarm :)

GetMesh()->SetOwnerNoSee(true);

This actually works only if you play, since in editor without play does not have any affect.. I dont see anything wrong here.. this should be work :)

more ▼

answered Mar 05 '18 at 07:47 AM

avatar image

AmphDev
1.5k 15 9 33

(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