TObjectPtr<T> with UInterface fails (can only be used with types derived from UObject) but... UInterface is derived from UObject

As the subject.

This was working in my project for the longest and then suddenly I start getting compile errors one day out of the blue.

The error is vague-monster because it does not point to the offending property, it points to a line of code in the unreal engine itself.

> static_assert failed: 'TObjectPtr<T> can only be used with types derived from UObject'

So I have to dig into my build stack and I see that its complaining about a line of code:
TObjectPtr<IMyInterface> MyVariable;

Digging into UInterface which my interface is derived from, I see clearly UInterface derives from UObject.

What gives here? Why did this suddenly start blowing up and what is the real problem? The interface IS derived from UObject.

1 Like

I can’t speak to why it “suddenly” started failing, but the assert that is happening is accurate.

Yes UMyInterface derives from UObject, but IMyInterface doesn’t.

If you want a variable like that you’d use TScriptInterface< IMyInterface >.

2 Likes

Ah yes good catch. IMyInterface is different from the U object. Thank you.

When I say suddenly failed, this particular C++ file has not changed in seven months with successful builds going daily, and now all of a sudden its marked for fail on the above. The interface and the file itself have not changed at all in that time.

Just had the same thing happen and it was driving me nuts, especially since the build error didn’t even go to the file that it was happening in…
I had my editor create a UInterface file for the first time as opposed to me creating it myself. I also now have an interface with a default implementation. Maybe this has something to do with it?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.