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. 

Character retuning none when attempting to access component.

I am still fairly new to coding and unreal so sorry if this is a bit of a dumb question but iv'e been trying to figure this out for a while and its driving me insane. So I have a pawn that I am having act as the character I play as and I have made a component that I want to handle the player input and movement. All components are created with the player constructor below.

 APlayerCharacter::APlayerCharacter()
 {
      // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
     CharacterRootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Character Root Component"));
     RootComponent = CharacterRootComponent;
 
     CharacterStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Character Static Mesh Component"));
     CharacterStaticMesh->SetupAttachment(RootComponent);
 
     CharacterMovementHandler = CreateDefaultSubobject<UCharacterMovementHandler>(TEXT("Character Movement Handler"));
 }

When I view the character in the blueprint editor I can see all of the components present, create references to them and call the functions within the component from the editor. These are my functions that are currently in my component.

 UCharacterMovementHandler::UCharacterMovementHandler()
 {
     CurrentCharacter = GetOwner();
     if (CurrentCharacter != nullptr)
     {
         UE_LOG(LogTemp, Warning, TEXT("Movment handler reporting for %s."), *CurrentCharacter->GetName())
     }
     else
     {
         UE_LOG(LogTemp, Warning, TEXT("Movment handler failed/not assigned."))
         return;
     }
 }
 
 void UCharacterMovementHandler::MoveForward(float Axis)
 {
     UE_LOG(LogTemp, Warning, TEXT("MoveForward test."));
 }
 
 void UCharacterMovementHandler::MoveLeft(float Axis)
 {
     UE_LOG(LogTemp, Warning, TEXT("MoveLeft test."));
 }

But my understanding is the access none means you are trying to access something that doesn't exist. However the logging that I added for the constructor for the appears saying that the component is there and reporting on the controlled pawn, however I cannot seem to get any of the functions within that component to work. One thing I read suggested it may be a naming conflict so I tried making several other components with different names and still had no luck.

So I am assuming that there is something small that I must be missing that would be causing this to not work, so after 2 days of testing and research I am trying to reach out and hoping someone can help me solve this. Thank you ahead of time.

Product Version: UE 4.19
Tags:
more ▼

asked Aug 24 '18 at 01:52 PM in C++ Programming

avatar image

kranatos13
5 2 1 3

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

3 answers: sort voted first

Upon further testing it turns out I am just unfamiliar with Unreal. Having the UPROPERTY() of EditAnywhere was the incorrect property for what I was trying to do, Making it BlueprintReadWrite or BlueprintReadOnly, which should have been obvious to me but it was my first time using a c++ component that wasn't BlueprintSpawnable. Live and learn.

more ▼

answered Aug 27 '18 at 03:12 PM

avatar image

kranatos13
5 2 1 3

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

There is a chance that your components are actually being garbage collected. When declaring them on your header file did you declare them as UPROPERTY()?

more ▼

answered Aug 24 '18 at 04:18 PM

avatar image

Bariudol
944 21 13 29

avatar image kranatos13 Aug 24 '18 at 04:21 PM

No none of them are declared as UPROPERTY.

avatar image Bariudol Aug 24 '18 at 04:35 PM

That is why they are being garbage collected. Make sure that when you declare a component it is declared as follows:

 UPROPERTY(EditAnywhere, Category = "Components")
 UStaticMeshComponent MyStaticMesh;
avatar image kranatos13 Aug 24 '18 at 06:19 PM

Not sure where my original reply is (had a screenshot of my character showing in the game, that the component was still attached to my pawn), but regardless this didn't seem to work. I had never known about this garbage collecting before so I read up a bit on it but it seems to me that it only does that if the engine thinks that component in this case, is no longer relevant but it doesn't seem like that would be the case if I am trying to constantly call a function from the component. Also to set my mind at ease I added a tick function to the component to add a log saying that its still there, still attached to the pawn and can still report every tick and its doing that, but it just refuses to let me access MoveForward().

avatar image kranatos13 Aug 24 '18 at 08:46 PM

That didn't seem to fix it. I still get spammed with:

"Blueprint Runtime Error: Accessed None trying to read property CharMoveHandler from function: 'ExecuteUbergraph_PlayerCharacter_BP' from node: Move Forward in graph: EventGraph in object: PlayerCharacter_BP with description: Accessed None trying to read property CharMoveHandler"

But from what you are saying, and my interpretation is that when the game starts and my character gets spawned, it makes my component, but then after its construction is it ending up getting deleted? That's what I thought also but when I look at the components of my player while spawned in the game its still listed: alt text

I also never heard about the garbage collection thing before now so I looked it up, and it also seems like it only does that when it sees a component is no longer being used but would that be the case due to the MoveForward() function continually being called, or am I just completely misunderstanding that?

avatar image kranatos13 Aug 24 '18 at 06:55 PM

As an update I went ahead and removed the creation of my component from my playercharacter cpp and made it blueprint spawnable and added it that way and it worked fine. Would that mean there could be something wrong with how I referenced my CharacterMovementHandler?

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

Upon further testing it turns out I am just unfamiliar with Unreal. Having the UPROPERTY() of EditAnywhere was the incorrect property for what I was trying to do, Making it BlueprintReadWrite or BlueprintReadOnly, which should have been obvious to me but it was my first time using a c++ component that wasn't BlueprintSpawnable. Live and learn.

more ▼

answered Aug 27 '18 at 03:11 PM

avatar image

kranatos13
5 2 1 3

(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