so to handle damage in a project i’m working on i have created a damage interface
for hitscan weapons its set up so it checks to see if what has been hit implements the damage interface and then it sends information through and tells what it hit to go hurt itself - this is done pretty much entirely done in blueprints
here is how it works on the weapon side
that then goes to the hit target that then sorts the damage out
for projectile weapons someone else did the code entirely in c++
and i’m trying to make it use the damage interface
how do I in c++ at the hit event check to see if what was hit implements the damage interface and then activate the event?
or should i just re-implement everything in blueprints (what do i use for hit detection on the blueprint side? i tried on component hit and on component begin overlap in a collision sphere component but it didn’t work for some reason)
If it is implemented in c++ casting an object to the I-Interface should not return nullptr;
// First check if the interface was implemented in c++ or BP. If it was only implemented in BP a c++ cast would return nullptr.
// Blueprint
if (OtherObject->Implements<UMyInterface>()) {
IMyInterface::Execute_ExecuteDoStuff(OtherObject);
}
// C++
else if (const IMyInterface* OtherInterface = Cast<IMyInterface>(OtherObject)) {
if (OtherInterface) {
OtherInterface->DoStuff();
}
}
// Else Not implemented
ah crap hang on I think i worded the question a bit off
I meant I am trying to see if the object that just got hit implements the interface
and then use the interfaces function event thingy
so
does implement interface true/false
if true run this
for the hitscan bits I worked on this, all works but some projectile based weapons someone else worked that they did in c++ I can’t quite figure out how to correctly shoehorn my system in there using blueprints
so i thought about just taking the code the other guy did and basically do the interface check and event triggering in there but I’m not 100% sure how to access blueprint stuff in c++
oh… Wait the interface itself is a blueprint asset? Port that to c++.