# How to cast from a normal Blueprint to a Data Blueprint?

**URL:** <https://forums.unrealengine.com/t/how-to-cast-from-a-normal-blueprint-to-a-data-blueprint/413644>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [January 3, 2018, 12:24pm UTC](https://forums.unrealengine.com/t/how-to-cast-from-a-normal-blueprint-to-a-data-blueprint/413644 "2018-01-03T12:24:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikegarn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mikegarn](https://forums.unrealengine.com/u/mikegarn)\
**Post date:** [January 3, 2018, 12:24pm UTC](https://forums.unrealengine.com/t/how-to-cast-from-a-normal-blueprint-to-a-data-blueprint/413644/1 "2018-01-03T12:24:54Z")

</div>

So this is probably a really fundamental question but I’ve been searching around and experimenting for a couple days and can’t figure out how to cast between blueprints that are not the Player Blueprint. I’ll attach a diagram below, but basically I’m trying to cast from a Weapon Pickup Blueprint to a Data Blueprint in order to set those variables inside the Pickup Blueprint. The Data Blueprint consists of several structs that categorize the weapon’s variables so it’s easier to manage when it comes time for them to go to many different places inside the Player Blueprint. From there if the player picks up that Pickup Blueprint, the Player Blueprint casts to the Pickup Blueprint to receive those variables. From there the player can modify those variables, stuff like changing magazine capacity or weapon accuracy. If the player drops that weapon a new weapon pick up is created with the modified variables inside. I hope that makes sense.

I’ve followed many tutorials on casting most of which have involved casting from the Player Blueprint, which is not my issue, I can do that correctly. So specifically I want to inherit the variables from a Data Blueprint into a Weapon Pickup Blueprint. If I can just get that figured out I should be golden. Do you guys have any solutions for this? A screenshot, or a tutorial, or documentation? Any help would be soooooo awesome. Thanks.

 ![225793-weaponpickupsystem-01.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/7/2/97234d53ff2b9c6dcef4ecf66945f962777cb8d1.jpeg)

---

<div class="post-metadata">

**Author:** ![Vizgin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vizgin](https://forums.unrealengine.com/u/Vizgin)\
**Post date:** [January 4, 2018, 5:23pm UTC](https://forums.unrealengine.com/t/how-to-cast-from-a-normal-blueprint-to-a-data-blueprint/413644/2 "2018-01-04T17:23:28Z")

</div>

Hi,

First of all, thank you for providing that figure. It was quite helpful in describing your question. Second, unfortunately, the approach you have in mind is just not possible! Casting is only done on the inheritance chain. What you want is to be able to change the parent of a class during runtime which is just **impossible**! In the context of object-oriented modeling, once an object is initialized, you **cannot** change its type **nor** can you change its inner relation. However, this doesn’t mean that you cannot accomplish what you want. All you need is just a little bit of modification in your original diagram. In fact, what you want can be even done in a very clear, neat, and somewhat generic and reusable manner and for that, you need a few key features of object-oriented modeling, specifically **inheritance** and **polymorphism**. I have answered very similar questions in the past few days (_[link1](https://answers.unrealengine.com/questions/742258/assign-pawns-to-controllers-from-multiple-classes.html), [link2](https://answers.unrealengine.com/questions/740688/problem-calling-custom-events-from-ai-behavior-tre.html), [link3](https://answers.unrealengine.com/questions/740538/how-to-manage-player-pawn-selection-for-a-racing-g.html), [link4](https://answers.unrealengine.com/questions/741604/freezing-character-after-overlap.html)_). I highly recommend that you take a look at them to better understand these concepts (you can even think of these questions as examples).

So how would you go about accomplishing this? You would at least need 4 blueprints: 2 for your base classes, and 2 for the children derived from them. They will have the following relationship

**BaseWeapon** ← **Weapon\_Type\_01**

**BaseCharacter** ← **Character\_Type\_01**

The ← sign here means that the operand on the right inherits from the operand on the left (e.g. **Weapon\_Type\_01** inherits from **BaseWeapon** ). I’m gonna stick with these names as they are more generic, though feel free to name your blueprints whatever that makes sense to you. I’m also only gonna focus on the two Base classes as their children can be as unique as you want and that’s not really of our concern here. Now, starting with the **BaseWeapon** , this blueprint would contain base variables and interfaces that are common to all your different types of weapons. You can simply create as many different weapons as you want from this. One interface function that this **BaseWeapon** probably needs to have is **Fire()**. Taking advantage of polymorphism, you would implement its common parts such as damaging the player in the **BaseWeapon** class and the unique part such as spawning a laser in its unique child. Any of your characters can simply call this **Fire()** method through **BaseWeapon** and it would automatically link to the appropriate weapon and fire it for you! Definitely refer to those link I provided to better understand how the polymorphism works. Similarly, create a **BaseCharacter** and base all your different types of characters on this.

Now comes the tricky part that you were doing wrong! Instead of trying to change inheritance relation of your classes, create a variable in your **BaseCharacter** and make it of type **BaseWeapon**. Let’s name it **PickedWeapon**. Now whenever your character picks any type of weapon that is based on **BaseWeapon** , you store it in this variable **PickedWeapon**. Think about this, _what does a character need to know about a gun?_ -Probably the number of available bullets and magazine capacity. These can be public variables and you can have getters for them so your character can read them. _What functions of it does a character need?_ -Just a fire button to press and fire that weapon (probably a reload function too)! A character doesn’t need to know how to process the bullets and fire them. It’s weapon’s responsibility! And that’s the beauty of object-oriented design! Whenever you want to fire, from within any of your unique characters, get this **PickedWeapon** variable that is inherited from **BaseCharacter** and call its function **Fire()**, which has its signature in **BaseWeapon** and its implementation in the unique children. The polymorphism will take care of it for you and link to the **Fire** method of the appropriate child weapon!

If you want to drop your weapon, call the drop function you have in your character, play the animation, and set this variable **PickedWeapon** to **null** (or **None** in blueprints terms).

There you go! A beautiful and generic system that would work with any weapon and any character you have that are based on these base classes.

Hope this helps 🙂

~Vizgin

---

<div class="post-metadata">

**Author:** ![mikegarn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mikegarn](https://forums.unrealengine.com/u/mikegarn)\
**Post date:** [January 4, 2018, 6:08pm UTC](https://forums.unrealengine.com/t/how-to-cast-from-a-normal-blueprint-to-a-data-blueprint/413644/3 "2018-01-04T18:08:06Z")

</div>

Ohhhh I see! What an interesting way to build this and way more modular than what I had in mind. I’ll check out those links tonight and return if I have anymore questions. Thanks so much Vizgin, you’re a hero!

---

<div class="post-metadata">

**Author:** ![Vizgin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vizgin](https://forums.unrealengine.com/u/Vizgin)\
**Post date:** [January 4, 2018, 6:12pm UTC](https://forums.unrealengine.com/t/how-to-cast-from-a-normal-blueprint-to-a-data-blueprint/413644/4 "2018-01-04T18:12:13Z")

</div>

You’re very welcome.

Please consider marking the question as resolved by checking that ckeckmark next to the answer if it helped resolving your issue. Thanks 🙂

---

<div class="post-metadata">

**Author:** ![mikegarn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mikegarn](https://forums.unrealengine.com/u/mikegarn)\
**Post date:** [January 5, 2018, 8:26pm UTC](https://forums.unrealengine.com/t/how-to-cast-from-a-normal-blueprint-to-a-data-blueprint/413644/5 "2018-01-05T20:26:16Z")

</div>

I want to make sure we’re on the same page. I’m working in Paper2d, so all I need are to set the variables from one blueprint to the Player Blueprint. Animations and weapon functions are all currently stored in the Player BP. I made another diagram to be a bit more specific what I’m trying to accomplish.

 ![226076-weaponpickupsystem-02.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/a/a/caa776ada3009e4e6693c62d8485dabe07f6e717.jpeg)

I realize I may still have to do it the way you described, but out of my own curiosity I want try it this way if possible.

---

<div class="post-metadata">

**Author:** ![mikegarn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mikegarn](https://forums.unrealengine.com/u/mikegarn)\
**Post date:** [January 8, 2018, 6:35pm UTC](https://forums.unrealengine.com/t/how-to-cast-from-a-normal-blueprint-to-a-data-blueprint/413644/6 "2018-01-08T18:35:11Z")

</div>

Ok I found a video that helped clear up my issue sending variables between Blueprints, it can most certainly be done, but out of simplicity and more control decided to change my method for my weapon system to something more like what Vizgin suggested. Here’s a link to the video I watched on Blueprint Communication and a link to the video I’m referencing to build my weapon system. I’m building this sucker in Paper2d so I’m not using skeletal sockets to hold the weapons but going to try and use Child Actor Components within the Player BP, and then set the desired Weapon BP as the Child Actor Class. It seems to be working… so far 😉

Blueprint Communication Tutorial [Blueprint Communications | Live Training | Unreal Engine - YouTube](https://www.youtube.com/watch?v=EM_HYqQdToE)

Blueprint based Weapon System Tutorial [UE4 Tutorial - Weapon Systems! - Part 1 - Basic Pick Up Blueprint - YouTube](https://www.youtube.com/watch?v=ZcvXm8uDEmk)
