I just start using unreal and have a quick question about how to properly call a function from another class.
In my project, there’s time that I want to destroy an object (a box for example)
#Character.h#
UPROPERTY(VisibleAnywhere, Category=Mesh)
class ABoxA* a; // reference to class BoxA
and when I call it in Character.cpp file
a->DestroyBox();
----------------
#BoxA.cpp#
void ABoxA::DestroyBox() {
Destroy();
}
It looks fine with IntelliSense but whenever I fire a function, it failed instantly.
If “Failed” means it crashed, then your ‘a’ variable is probably null.
The editor will tell you about any errors when you compile it, except for that. Make sure your a variable isn’t null, possibly using the method shown above.
Also if you read the crash log, it usually gives helpful error messages.
He’s trying to apply Unity basic concepts and gonna have a hard time by doing so.
Is easier route to simply ignore your Unity experience and learn how Unreal works instead.
May i ask why you put a Random Function into the index parameter? If you want to achieve that messages don’t overwrite previous ones, then you can just
put in a “-1”
@Topic: I’m also pretty sure you are calling the function without having an actor in it.
That thing you declared there is a pointer! You may want to read up the pointer usage in C++.
C# is way simpler in that term, but also doesn’t offer that much control.