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 can I use FObjectFinder to set the property of a structure

I have a struct that I made called FInventorySlot. It needs to have two properties, one is an integer and the other is the class of a blueprint called BP_PickUpItem_MAIN. It is not a c++ class and inherits from another blueprint class called interactable which is also not a c++ class. Interactable then inherits from AActor.

I am aware of the issue of trying to use blueprint created classes in C++ but I figure this might be different due to the fact that I just need the class.

I'm having an issue setting the class property inside the constructor with FObjectFinder. When it is inside the constructor and has been built it crashes when any blueprint graph is opened. Here is some code for my struct:

    USTRUCT(BlueprintType)
     struct FInventorySlot
     {
         GENERATED_BODY()
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory")
         TSubclassOf<UObject> ItemClass;
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory")
         int32 StackAmount;
 
     FInventorySlot()
     {
         static ConstructorHelpers::FObjectFinder<UClass> BlueprintClass(TEXT("Class'/Game/Evolution/Actors/Pickups/BP_PickUpItem_MAIN.BP_PickUpItem_MAIN'"));
         ItemClass = BlueprintClass.Object;
         StackAmount = 1;
     }
 };

The code for the struct works perfect when I comment out the top two lines of my FInventorySlot constructor. How can I change the class dynamically like this of a structure?

Product Version: UE 4.14
Tags:
more ▼

asked Jan 09 '17 at 09:50 AM in C++ Programming

avatar image

ALegendsTale
113 4 9 13

avatar image p30virus Mar 13 '19 at 01:47 AM

Hi, you found a solution or workaround this??

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

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