Cpp interface crashes the editor when called.

I’v been using this guid: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

And when ever I call a function, The editor crashes with this message:
Assertion failed: O->GetClass()->ImplementsInterface(URMInterface::StaticClass())

And pointing on the funciton call line ( Execute_… ).

Code:



auto interface_ = Cast<IRMInterface>(actor_); 
if (interface_)
{
interface_->Execute_StoreLocation(this); //Crashes here
}


Any idea why this is happening?

Also notice the interface is part of a plugin i’m working in and it is in the plugins folder.

You should include your interface and class definitions, as the crash error makes it sound like your interface it not setup correctly.

You probably wanted to pass actor_ to Execute_StoreLocation instead of this (at least that would make more sense in regards to the cast).
The assertion essentially tells you that the UObject (this) passed to Execute_StoreLocation does NOT implement the interface although it is required to implement it. So in case passing this was intended, make sure that the class implements the IRMInterface.

It works now. I had to pass “actor_” instead of “this” into the function. Like this:
interface_->Execute_StoreLocation(actor_);
Thanks for the help guys.

Question? Why are you passing the class object too itself?

You are casting actor_ to interface_ then passing actor into the Execute_StoreLocation method of Interface.

I should have probably pointed that out too, apologies. The Execute_* functions automatically generated by the UnrealHeaderTool are static and have an UObject* argument. While you don’t have to call them on an instance, it’s perfectly fine to do so although the coding standards you adhere to may discourage that.
Note that it’s still a good idea to cast and check the interface_ first. Otherwise you could easily trigger an assertion (if the UObject* is NULL or the class does not implement the interface).


auto interface_ = Cast<IRMInterface>(actor_); 
if (interface_)
{
	IRMInterface::Execute_StoreLocation(actor_);
}