I’m struggling with coming over to Unreal Engine 4 with my C++ knowledge so hopefully you guys could be kind enough to answer some of my silly questions.
All I want to do is to be able to access members/functions of one class from another, after following on from this tutorial:
For example, at the moment I’ve got all my Action/Axis input controls in a FPSCharacter.cpp and one of them executes the function within FPSCharacter called Output() when ‘O’ is pressed. I want this Output() function to be able to print out a value from a different class called FPSProjectile either by directly accessing the member or perhaps using a getValue() function.
So the basic question is, how can I allow FPSCharacter to access FPSProjectile members/execute FPSProjectile functions?
I hope that makes sense, thanks a lot for the help!
First of, you need access to your FPSProjectile object.
If it’s spawned dynamically and FPSCharacter just can’t have pointer to it, you can use level actors iterator to find your projectile and then call or access any FPSProjectile members. If you spawn it within FPSCharacter, you can store pointer to projectile and then use it when needed, make sure you check it against null all the time you’re trying to access it, since projectile could be destroyed by the time you access it.
Thanks for the help guys but so far I feel like I’m going in circles a little bit, just confusing myself.
I just want to bring it right down to basics quickly and ask if what I am doing wrong
Got a class called FPSTest with a function called FuncTest() that prints out some text to the screen with AddOnscreenDebugMessage.
I want to be able to execute that function from within my FPSCharacter class, simple right? Not for me!
I thought it would be as simple as writing something like (simplified)