# How to implement C++ funcions and call it in blueprints

**URL:** <https://forums.unrealengine.com/t/how-to-implement-c-funcions-and-call-it-in-blueprints/418732>\
**Category:** Blueprint\
**Tags:** calling-a-function, unreal-engine, CPP, Blueprint, question\
**Created:** [March 1, 2018, 11:56pm UTC](https://forums.unrealengine.com/t/how-to-implement-c-funcions-and-call-it-in-blueprints/418732 "2018-03-01T23:56:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RHERWOLF](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RHERWOLF](https://forums.unrealengine.com/u/RHERWOLF)\
**Post date:** [March 1, 2018, 11:56pm UTC](https://forums.unrealengine.com/t/how-to-implement-c-funcions-and-call-it-in-blueprints/418732/1 "2018-03-01T23:56:17Z")

</div>

I need to do something like it.

```
float Level( int Xp ){
    float temporary = Xp ;
    temporary = sqrt( temporary ) ;
    temporary = sqrt( temporary ) ;
    return min( 1.0f+temporary , 100.0f );
}

```

![232485-bp-example.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/4/5/b457cded6dc38fc4305f2b5e3efce938492e1ca1.png)

How to do it?

**From the files creation until the function call.**

Is needed a C++ class? Or no?

Can it be like a common C++ function library?

Note: I’d forged the image.

---

<div class="post-metadata">

**Author:** ![SharksArePeople2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SharksArePeople2](https://forums.unrealengine.com/u/SharksArePeople2)\
**Post date:** [March 2, 2018, 12:37am UTC](https://forums.unrealengine.com/t/how-to-implement-c-funcions-and-call-it-in-blueprints/418732/2 "2018-03-02T00:37:26Z")

</div>

In the header file you need to make your method a UFunction [UFunctions | Unreal Engine Documentation](https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Functions/)  
For example

```
    UFUNCTION(BlueprintCallable)
    float Level(int Xp);
```

---

<div class="post-metadata">

**Author:** ![RHERWOLF](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RHERWOLF](https://forums.unrealengine.com/u/RHERWOLF)\
**Post date:** [March 2, 2018, 12:53am UTC](https://forums.unrealengine.com/t/how-to-implement-c-funcions-and-call-it-in-blueprints/418732/3 "2018-03-02T00:53:15Z")

</div>

Can you answer about the files? How to make the function be found by the blueprint? Need to be in the same folder?

---

<div class="post-metadata">

**Author:** ![RHERWOLF](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RHERWOLF](https://forums.unrealengine.com/u/RHERWOLF)\
**Post date:** [March 2, 2018, 12:54am UTC](https://forums.unrealengine.com/t/how-to-implement-c-funcions-and-call-it-in-blueprints/418732/4 "2018-03-02T00:54:39Z")

</div>

Can be only a “.h”? How to make the unreal engine editor see the “.cpp” or “.h”?

---

<div class="post-metadata">

**Author:** ![SharksArePeople2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SharksArePeople2](https://forums.unrealengine.com/u/SharksArePeople2)\
**Post date:** [March 2, 2018, 5:44am UTC](https://forums.unrealengine.com/t/how-to-implement-c-funcions-and-call-it-in-blueprints/418732/5 "2018-03-02T05:44:58Z")

</div>

Header files contain definitions of Functions and so the UFUNCTION only needs to be in the .h file. At the top of the link it says “UFunctions are declared in the .h class header file”. Once you add the code in the above post to your header file go to your .cpp file and implement the method, compile your code then you should be able to call the method in blueprints as long as it’s in scope.

---

<div class="post-metadata">

**Author:** ![RHERWOLF](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RHERWOLF](https://forums.unrealengine.com/u/RHERWOLF)\
**Post date:** [March 2, 2018, 10:30am UTC](https://forums.unrealengine.com/t/how-to-implement-c-funcions-and-call-it-in-blueprints/418732/6 "2018-03-02T10:30:30Z")

</div>

This video answered my question.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/d/a/edabd3334f9ded57c668d3309930d9297a7350c3.jpeg "Writing a custom C++ function for BP use in UE4") ](https://www.youtube.com/watch?v=4CgCJsThsWU)
