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"

After C++ inherited BP compile: compiled object becomes invalid


I have a C++ UClass and inherited a BP from it. Another C++ class, which is a widget, not a UObject, has a pointer to an object of that UClass. When I manipulate it in the editor, it is fine. However, when I recompile the inherited BP while the widget is still open, the pointer that the widget owns becomes invalid and only when I close the window and re-open it or otherwise reconstruct the widget the pointer becomes valid again.

It appears that when recompiling, object references to objects of that class first become invalid while the compiler updates, and then get fixed again - with other UObjects. Since widgets (Slate) are not UObjects, my guess is that that pointer does not update its reference automatically because of it.

How do I tell my C++ system it needs to reconstruct after a BP compile? Or if there's another, proper way, how do I fix this? Right now I have a raw pointer to that UObject, would using a TWeakObjectPtr help?

EDIT: I got more information now: the object that is being accessed while it is invalid isn't a nullptr. The original class name of the BP class is "CameraEvent_C", however the one being accessed is "REINST_CameraEvent_C" which seems like my assumption correct; the old object is supposed to be reinstanced, but something goes wrong, probably because the widget isn't a UObject.

2nd EDIT: Wrapping the pointer as a TWeakObjectPtr results in the object being "STALE", and if accessed, a nullptr.To clarify the question: How do I properly update references to UObjects of objects that aren't UObjects, since compiling the BP of the latter results in reinstancing the objects, which seemingly doesn't work with non-UObjects.

Product Version: UE 4.22
more ▼

asked May 22 '19 at 02:30 PM in C++ Programming

avatar image

89 6 12 17

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

1 answer: sort voted first

Yes, your assumption is correct. When you compile a BP, all instances of that class are destroyed and re-initialized. The Editor has an "OnObjectsReplaced" delegate that is called when that happens (it passes you the old UObject* and the new one to replace it with).

I would use a TWeakObjectPtr and then have your slate object just poll every frame to make sure that object is valid (you can just call "IsValid()" on the WeakObjectPtr), and if not - to fix it up.

Or you can have your Slate widget register with OnObjectsReplaced and then fix it up that way.

more ▼

answered May 22 '19 at 02:47 PM

avatar image

1.6k 34 14 48

avatar image Quexlaw May 22 '19 at 04:06 PM

I don't think I can properly fix this via tick, but the OnObjectsReplaced delegate should do the job just fine. I'll accept your answer once I've tested and confirmed it working, although I believe it should be the solution. Thanks!

avatar image Quexlaw May 22 '19 at 05:43 PM

Can confirm now. Works like a charm. The delegate can be found in EditorEngine.h, for all people seeing this.

(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