Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

Product Version: UE 4.7
more ▼

asked Jun 10 '15 at 09:10 AM in C++ Programming

avatar image

1 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hi Adhordal,

Welcome to UE4's C++ programming. First thing you should probably look at would be these two pages:

https://docs.unrealengine.com/latest/INT/Programming/Introduction/index.html https://www.unrealengine.com/blog/unreal-property-system-reflection

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:

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Box Component)
 UBoxComponent* BoxComponent;

After that, you'll need to initialize it in the .cpp, inside of the constructor like so:

 BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Box Component"));

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!

Matthew Clark

more ▼

answered Jun 10 '15 at 05:53 PM

avatar image Adhordal Jun 10 '15 at 10:25 PM

Matthew, thank you for helping me! The getting started from unity page was a gold mine. I feel I know a lot more now, although experimentation will dictate how much i progress now. I managed to get the box component to work, but I must confess i still find the Custom Anim Notify quite difficult to be used in c++. Thank you for you help.

avatar image Matthew J Jun 11 '15 at 03:19 PM

Practice makes perfect and that has never been more true than with C++. If you run into any more issues, please feel free to post another question here and either we or the community will try to help you.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question