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"

How to properly set a defaults for a C++ class in BP

I was using the VisibleDefaultsOnly option in my UPROPERTY macros, which allowed me to set the defaults for my variables in a data-only blueprint. Then something happened*. Essentially, I couldn't set default class values in my blueprint when I built the project that time, and haven't been able to since. Switching the macro to EditDefaultsOnly, for example, isn't letting my skeletal mesh components work correctly and this has been an unfortunate turn from the previously perfect macro settings. Is there anything else that I'm missing which would prevent VisibleDefaultsOnly from allowing me to set defaults? This has affected all of my classes as far as I can tell. Here is a photo of the unsettable defaults:

alt text

Here is the class: (BaseWeaponDrop.h)

 class Afpchar;
 class ABaseWeapon;
 
 #pragma once
 #include "GameFramework/Actor.h"
 #include "BaseWeaponDrop.generated.h"
 
 UCLASS()
 class ABaseWeaponDrop : public AActor
 {
     GENERATED_BODY()
 
 public:
     
     UPROPERTY(EditDefaultsOnly, Category = "Main")
     USkeletalMeshComponent* WeaponMeshComponent;
     
     UPROPERTY(EditDefaultsOnly, Category = "Main")
     UShapeComponent* WeaponCollision;
 
     UPROPERTY(EditDefaultsOnly, Category = "Main")
     TSubclassOf<ABaseWeapon> ActualWeapon;
 
     UPROPERTY()
     int32 LoadedAmmo;
 
     UPROPERTY()
     int32 TotalAmmo;
 
     ////MODEL MANAGEMENT////
 
     UPROPERTY(EditDefaultsOnly, Category = "Mesh Management")
     USkeletalMesh* LeftFPMesh;
 
     UPROPERTY(EditDefaultsOnly, Category = "Mesh Management")
     USkeletalMesh* RightFPMesh;
 
     UPROPERTY(EditDefaultsOnly, Category = "Mesh Management")
     USkeletalMesh* TPMesh;
 
 public:
 
     ABaseWeaponDrop();
 
     virtual void BeginPlay() override;
 
     virtual void Tick(float DeltaSeconds) override;
 
     UFUNCTION(BlueprintCallable, Category = "Actions")
     virtual ABaseWeapon* Pickup(Afpchar* InstigatingCharacter);
 
     virtual void Config(int32 NewLoadedAmmo, int32 NewTotalAmmo);
 
     ////ACCESSORS////
 
     UFUNCTION(BlueprintCallable, Category = "Access")
     virtual int32 GetLoadedAmmo() { return LoadedAmmo; };
 
     UFUNCTION(BlueprintCallable, Category = "Access")
     virtual int32 GetTotalAmmo() { return TotalAmmo; };
 
     FORCEINLINE UShapeComponent* GetWeaponCollision() const { return WeaponCollision; }
 
     FORCEINLINE USkeletalMesh* GetLeftFPMesh() const { return LeftFPMesh; }
 
     FORCEINLINE USkeletalMesh* GetRightFPMesh() const { return RightFPMesh; }
 
     FORCEINLINE USkeletalMesh* GetTPMesh() const { return TPMesh; }
 
 };
 

BaseWeaponDrop.cpp

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "halc.h"
 #include "fpchar.h"
 #include "Private/BaseWeapon.h"
 #include "Private/BaseWeaponDrop.h"
 
 ABaseWeaponDrop::ABaseWeaponDrop() //can call tick be set to false?
 {
     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = false;
     
     //initialize meshes
     //LeftFPMesh = CreateDefaultSubobject<USkeletalMesh>(TEXT("Left-handed FP Mesh"));
     //RightFPMesh = CreateDefaultSubobject<USkeletalMesh>(TEXT("Right-handed FP Mesh"));
     //TPMesh = CreateDefaultSubobject<USkeletalMesh>(TEXT("Third Person Mesh"));
 
     WeaponMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMeshComponent34"));
     RootComponent = WeaponMeshComponent;
 
     WeaponCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("DroppedWeaponCollision"));
     WeaponCollision->AttachTo(RootComponent);
 
     WeaponMeshComponent->SetSimulatePhysics(true);
     WeaponMeshComponent->SetWalkableSlopeOverride(FWalkableSlopeOverride(WalkableSlope_Unwalkable, 0.f));
     WeaponMeshComponent->CanCharacterStepUpOn = ECB_No;
 }
 
 void ABaseWeaponDrop::BeginPlay()
 {
     Super::BeginPlay();
 
 }
 
 void ABaseWeaponDrop::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
 }
 
 ABaseWeapon* ABaseWeaponDrop::Pickup(Afpchar* InstigatingCharacter) //can I get the drop destruction done here?
 {
     UWorld* const World = GetWorld();
     if (World != NULL)
     {
         auto const Loc = GetActorLocation();
         auto const Rot = GetActorRotation();
 
         FActorSpawnParameters WeaponSpawnParameters = FActorSpawnParameters();
         WeaponSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
         ABaseWeapon* HeldWeaponCopy = World->SpawnActor<ABaseWeapon>(ActualWeapon, Loc, Rot, WeaponSpawnParameters); //use template instead?
         HeldWeaponCopy->Config(LoadedAmmo, TotalAmmo, InstigatingCharacter);
         Destroy();
         return HeldWeaponCopy;
 
     }
     else return NULL;
 }
 
 void ABaseWeaponDrop::Config(int NewLoadedAmmo, int NewTotalAmmo)
 {
     LoadedAmmo = NewLoadedAmmo;
     TotalAmmo = NewTotalAmmo;
 }


  • can't exactly remember... which is part of the problem but bear with me (it might have been me using the in-engine compile button, or getting rid of some USTRUCTS).

Product Version: UE 4.11
Tags:
more ▼

asked Jul 23 '16 at 12:01 AM in C++ Programming

avatar image

MikeBelousov
1 1 1

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

0 answers: sort voted first
Be the first one to answer this question
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