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"

SetPropertyValue() corrupts object?!

Problem:

If I create an object and set a property using the reflection system the object becomes invalid - it fails an assert in ConditionalDestroy() - it is caused because when the BeginDestroy() function is called on the object somehow the PostLoadSubobjects() is called instead, and BeginDestory() isn't called at all.

Code I used:

 UCLASS(BlueprintType, EditInlineNew)
 class TPSTEST_API UTestObjectBase : public UObject
 {
     GENERATED_BODY()
     
 protected:
 
     UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Params)
     bool bTestParam = true;
 };


In character Header:

 UPROPERTY()
 class UTestObjectBase* ObjectPtr;

Character BeginPlay:

 //////////////////////////////////////////////////////////////////////////
 void ATPSTestCharacter::BeginPlay()
 {
     ObjectPtr = NewObject<UTestObjectBase>(this, UTestObjectBase::StaticClass());
 
     UBoolProperty* Property = Cast<UBoolProperty>(ObjectPtr->GetClass()->FindPropertyByName("bTestParam"));
     if (Property != nullptr)
         Property->SetPropertyValue(reinterpret_cast<void*>(ObjectPtr), false);
 }
 


Easiest way to reproduce:

  1. Create a C++ tps template project (4.15)

  2. Paste the attached files (overwriting the default character .h/.cpp).

  3. Start the game in editor

  4. Press esc to stop it

Interesting part is the fact that the error looks totally random, but I had exactly the same results in a much more complicated environment. Did I miss something?

Product Version: UE 4.15
Tags:
testfiles.zip (2.2 kB)
more ▼

asked Mar 09 '17 at 01:07 PM in Bug Reports

avatar image

Elathan
406 20 27 57

avatar image Elathan Mar 09 '17 at 01:29 PM

Edit: I guess I misunderstood how SetPropertyValue() works, and it expects a pointer to bTestParam and not a pointer to the object containing it? I still did not find the right way to do this, but I'll keep looking...

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

2 answers: sort voted first

I think issue might be cast, void* should accept any pointer type (including function pointers) as it's ambiguous type just containing memory address and it can take it from any other pointer without casting (in other word void* is a "base class" for any pointer for compiler). you might also try using _InContainer version with index 0 i remeber i had similar isues with nomal function yet the container one worked ok.

more ▼

answered Mar 09 '17 at 01:40 PM

avatar image

Shadowriver
33.9k 916 164 1093

avatar image Elathan Mar 09 '17 at 01:50 PM

Yes, I found the problem too. _InContainer expects an Object pointer (ObjectPtr in this case), but the simple version expects a pointer to the variable itself (bTestParam in this case).

It isn't really clear, but whatever, at least I figured it out :P

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

Using SetPropertyValue_InContainer() instead of SetPropertyValue() solved the problem.

more ▼

answered Mar 09 '17 at 01:36 PM

avatar image

Elathan
406 20 27 57

(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