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"

Mesh is private member

Maybe somebody can help me? Mistake: 'Mesh' is a private member of 'ACharacter'

"Learning c++ by creating games with ue4" book


pragma once

 #include "CoreMinimal.h"
 #include "GameFramework/Actor.h"
 #include "Monster.h"
 #include "Runtime/Engine/Classes/Components/StaticMeshComponent.h"
 #include "Runtime/Engine/Classes/Components/BoxComponent.h"
 #include "Runtime/Engine/Classes/Components/PrimitiveComponent.h"
 #include "MeleeWeapon.generated.h"
 class AMonster;
 class NONAME_API AMeleeWeapon : public AActor
     // Sets default values for this actor's properties
     AMeleeWeapon(const class FObjectInitializer& PCIP);
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
     // Called every frame
     virtual void Tick(float DeltaTime) override;
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category= "MeleeWeapon")
     float AttackDamage;
     TArray<AActor*> ThingsHit;
     bool Swinging;
     AMonster *WeaponHolder;
     UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite, Category= "MeleeWeapon")
     UBoxComponent *ProxBox;
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "MeleeWeapon")
     UStaticMeshComponent *Mesh;
     UFUNCTION(BlueprintNativeEvent, Category = "Collision")
     void Prox( class UPrimitiveComponent* HitComp, class AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &  SweepResult );
     void Swing();
     void Rest();


 #include "Monster.h"
 #include "Avatar.h"
 #include "Runtime/CoreUObject/Public/UObject/UObjectGlobals.h"
 #include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
 #include "Runtime/Engine/Classes/Engine/SkeletalMeshSocket.h"
 #include "Runtime/Engine/Classes/Components/StaticMeshComponent.h"
 #include "MeleeWeapon.h"
 // Sets default values
     // 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;
 void AMonster:: PostInitializeComponents()
     Super:: PostInitializeComponents();
         MeleeWeapon=GetWorld()->SpawnActor<AMeleeWeapon>(BPMeleeWeapon, FVector(),FRotator());
             const USkeletalMeshSocket *socket=Mesh->GetSocketByName("ik_hand_rSocket"); //MISTAKE
             socket->AttachActor(MeleeWeapon, Mesh ); //MISTAKE

Product Version: UE 4.20
more ▼

asked Dec 20 '18 at 08:24 PM in C++ Programming

avatar image

Murphy Diana
10 2 3

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

2 answers: sort voted first

The "Mesh" variable you are trying to access is not the one from the weapon but of the character so you should use GetMesh(); if you want to access the one from the weapon you should use "MeleeWeapon->Mesh" ( but i think thats nit the case )

more ▼

answered Dec 21 '18 at 03:09 AM

avatar image

1.5k 14 18 32

avatar image Murphy Diana Dec 21 '18 at 09:42 PM

Thank you!

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

by default everything in your class is private.

You need to set its Access Specifier.

Those private, protected, or public you see in header files.


  class Monster;
  Class AMeleeWeapon
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "MeleeWeapon")
     UStaticMeshComponent *Mesh;

adding the public will let you access the Mesh from anywhere.

Quick breakdown of the 3:

  • public: Can be accessed from anywhere you can get a ref to this class

  • private: Even with a ref to this class these won’t show.

  • protected: Private but accessible from Child Classes.

more ▼

answered Dec 20 '18 at 07:15 PM

avatar image

1.7k 8 4 8

avatar image Murphy Diana Dec 20 '18 at 07:43 PM

Yes, thanks, I'm sorry, that is my fault , insufficient information about the problem, I updated the information

avatar image Murphy Diana Dec 20 '18 at 07:54 PM

Maybe you can try to help me again?

avatar image Evigmae Dec 20 '18 at 08:43 PM

I see you're declaring the UStaticMeshComponent in the .h, But are you actually creating the component anywhere?

Because you seem to be trying to access an empty pointer.

avatar image Murphy Diana Dec 20 '18 at 09:03 PM

Sorry, my English isn't good, but maybe you ask about this:



Mesh = PCIP.CreateDefaultSubobject(this, TEXT("Mesh")); RootComponent = Mesh;


That all from "Learning c++ by creating games with ue4" book, I'm just trying to repeat

(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