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"

ActorComponent gets none in blueprint

Hello everyone,

I have written an UInventoryComponent class which inherits from UActorComponent. I register it to my character in its constructor this way:

 Inventory = CreateDefaultSubobject<UInventoryComponent>(TEXT("InventoryComponent"));


InventoryComponent.h:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "Components/ActorComponent.h"
 #include "Item.h"
 #include "InventoryItem.h"
 #include "InventoryComponent.generated.h"
 
 class AItemActor;
 
 UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
 class RPS_API UInventoryComponent : public UActorComponent
 {
     GENERATED_BODY()
 
 public:    
     // Sets default values for this component's properties
     UInventoryComponent();
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory")
     TArray<UInventoryItem*> items;
 
 protected:
     // Called when the game starts
     virtual void BeginPlay() override;
 
 public:    
     // Called every frame
     virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
     UFUNCTION(BlueprintCallable)
         void AddItemActor(AItemActor * itemActor);
     UFUNCTION(BlueprintCallable)
     void AddItem(TSubclassOf<UItem> item,int number=1);
     UFUNCTION(BlueprintCallable)
     void DropItem(UInventoryItem *iItem);
 
     UFUNCTION(BlueprintCallable)
         void RemoveItem(UItem *item);
     UFUNCTION(BlueprintCallable)
         TArray<UInventoryItem*> GetItems(TSubclassOf<UItem> item);
     UFUNCTION(BlueprintCallable)
         int GetItemCount(TSubclassOf<UItem> item);
     UFUNCTION(BlueprintCallable)
         bool HasItem(TSubclassOf<UItem> item);
 };
 

however, when I restart the engine or change my characters c++ class, this Inventory component becomes None in blueprint. It throws error when I try to use it.

The solution I found was to remove the CreateDefaultSubObject line, then compile, then re-add the line again, and compile, and everything works fine. This, as you notice, is a boring process and I believe this is not the expected behavior of the engine. If I add the component from blueprint (not from c++ constructor) I never have any problem.

What may be the solution? Thanks

Product Version: UE 4.21
Tags:
more ▼

asked Dec 29 '18 at 09:36 PM in C++ Programming

avatar image

Epetha
1

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

I had kind of same issue about overlap/hit events. I think, this is about hot reload. I couldn't find any solution, however, the user "NoCodeBugsFree" suggested that re-parenting BP class to another class and then going back to the original class solves the issue sometimes. So, it looks like there is no solution. When it happens, closing and reopening editor should solve the issue.

Here is my similar issue: https://answers.unrealengine.com/questions/848293/view.html

more ▼

answered Dec 29 '18 at 10:34 PM

avatar image

Core21.
66 2 3 7

(comments are locked)
10|2000 characters needed characters left

Did you created blueprint of your character class, or c++ version?

I noticed an issue in blueprints, inherited from custom c++ classes, that when you add/change something to its constructor, you must recreate blueprint asset. It seems that blueprint is not updated with new changes So, I fixed it with not creating blueprints from that classes at all, or creating them only when I sure that it finished.

more ▼

answered Dec 30 '18 at 06:57 AM

avatar image

redbox
4.2k 79 16 102

(comments are locked)
10|2000 characters needed characters left
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