C++ programming guidance for Noob
Hello everyone! Adhordal here. I have picked up Unreal Engine 4 and after enjoying the wonderful editor, i decided to jump into programming gameplay. I have worked with Unity 5 before and became quite proficient with it, but now that i have switched to UE4 i am having difficulty adjusting. I have some questions for basics things in c++ and It'd be great if you could help me. I have searched quite a lot for both of the following problems but was unable to find anything to help me understand/overcome the problems. 1. How to do I make a function in c++ be called from an Anim Notify I have set up in the Animation Blueprint of the blueprint that derives from the c++ class. I was able to work around this by doing specific things related to the notifies in the blueprint and connect them to the c++ class but I'm curious as to how i can get that to work in pure c++. 2. I have placed a box collider component in the blueprint class viewport that derives from my c++ class. It will be used to detect collision with an enemy and apply damage on contact. The problem is that i don't know how to reference that box in my c++ code. I tried setting a pointer in the code with TSubobjectPtr but an error came up saying that that was deprecated. I tried with: class UBoxComponent* swordCollider ... Set to public and editable in the blueprint so I could set it to the swordCollider within the blueprint, But no luck. It doesn't even appear in the blueprint properties(even after compiling and restarting ue4)
Please, if anyone could help me with these problems I would be grateful.
Thank you Adhordal
asked Jun 10 '15 at 09:10 AM in C++ Programming
Welcome to UE4's C++ programming. First thing you should probably look at would be these two pages:
One of the biggest things to understand is the reflection system which is what is explained in that second link. To access a variable or a function in the editor/blueprints, you'll need to declare UPROPERTY or UFUNCTION first with the correct specifiers, such as EditAnywhere or BlueprintReadWrite for UProperties and BlueprintCallable for UFunctions.
As for your second question, the reason that this UBoxComponent can't be accessed in code when added to the blueprint is because the class itself doesn't know that the blueprint exists, let alone anything added to it. If you wish to use the UBoxComponent in code, you'll need to declare it in the .h like so:
After that, you'll need to initialize it in the .cpp, inside of the constructor like so:
This should allow it to be seen in any blueprints based off this class while also being editable/callable in C++.
Another good link that would be useful if you're familiar with Unity would be this: https://docs.unrealengine.com/latest/INT/GettingStarted/FromUnity/
I hope this information helps!
answered Jun 10 '15 at 05:53 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here