查看: 780|回复: 12

[可视化蓝图脚本] 【Blueprint Casting | Unreal Engine】

[复制链接]

1

主题

342

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
75866
发表于 2016-6-27 15:58:48 | 显示全部楼层 |阅读模式



This page covers how to use Blueprint Casting to communicate with different Blueprints and share information. In this example we allow the player to shoot an object, making it smaller each time it is hit. Each time the object is hit, it also notifies the Character Blueprint and increases the player's movement speed.

For this guide we are using the Blueprint First Person template with Starter Content enabled.

Inside the Viewport select one of the LargeCube meshes, then in the Details panel click the Blueprint/Add Script button.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



At the confirmation window that appears, click Ok to use the default name and create the Blueprint.

In the Content Browser under Content/FirstPersonBP/Blueprints, open the FirstPeronProjectile Blueprint.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



This is the Blueprint for the projectile that is launched when the player fires the weapon during gameplay.

Locate the Event Hit node and drag off the Other pin then search for and add the Cast To LargeCube_Blueprint node.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



On the Event Hit node, the Other pin refers to the other Actor that was hit. By using the Cast To node, we are checking to see if it is indeed the LaregCube_Blueprint that was the other Actor that was hit. If it is, we can access it and execute any Events or Functions within the Blueprint, change Variable values inside of it, or change the properties of the Components that are inside the Blueprint.

Off the As Large Cube Blueprint pin, use Get Static Mesh Component and then Set World Scale 3D and connect as shown.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



After we Add Impulse at Location we are then casting to the Large Cube Blueprint and getting the Static Mesh Component inside it (the actual Cube) and setting a new World Scale 3D value for it. Currently the New Scale is set to 0 however we will reduce the size of the Large Cube Blueprint each time it is hit.

Off Static Mesh Component use Get World Scale and connect to a Vector * Float pin (set to 0.5) then plug into New Scale.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



This will get the current World Scale of the cube and multiply it by .5 (or half its current size) each time it is hit, reducing its size.

Right-click in the graph and add a Get Player Character node, then off Return Value, Cast To FirstPersonCharacter.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



Here we are checking if the player character is using the FirstPersonCharacter Blueprint, which by default is the case with this template. By doing so we can now access the Events, Functions, Variables or Properties of the player character and modify them.

Connect the Set World 3D node to the Cast To FirstPersonCharacter node.

Off the As First Person Character pin, add the Get Character Movement node.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



We are going to adjust the character's speed whenever they hit the Large Cube, making them run faster.

Off the Character Movement node, add a Set Max Walk Speed and Get Max Walk Speed node.

Off the Get Max Walk Speed, use a Float + Float node (set to 200) then connect that to the Set Max Walk Speed pin.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



Once you have connected the nodes as shown above, this will allow the player character to move faster each time the cube is hit.

For both of the Cast To nodes, connect the Cast Failed pins to the Destroy Actor node.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



In the event that the player hits something that is not the Large Cube, we still want to call the Destroy Actor node to destroy the projectile. When hitting the Large Cube, in the event that it is not the First Person Character that hit the cube, we also still want to destroy the projectile.

The ending sequence for the Projectile Blueprint should look similar to below.

【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]




Click image for full view.

We used Reroute Nodes to adjust the flow of our wires for clarity, but your connections should be the same.

Click Compile and Save, then the Play button to play in the editor.

Each time you shoot the Large Cube Blueprint, it will reduce in size and your character will move faster.

For more information on Casting and usage cases, refer to the Related Topics section below.



   



   
【虚幻4翻译文档-Blueprint Casting | Unreal Engine】[虚幻4中文文档]



      




   


      相关页面

  




       Casting








      蓝图交互的用法








      蓝图用户指南




回复

使用道具 举报

0

主题

841

帖子

2774

积分

vip会员

Rank: 1

积分
2774
发表于 2016-7-2 19:57:33 来自手机 | 显示全部楼层
哈哈哈好大呀
回复 支持 反对

使用道具 举报

0

主题

824

帖子

2739

积分

vip会员

Rank: 1

积分
2739
发表于 2016-7-3 13:06:16 | 显示全部楼层
楼主好人!
回复 支持 反对

使用道具 举报

0

主题

842

帖子

2790

积分

vip会员

Rank: 1

积分
2790
发表于 2016-7-4 07:57:03 | 显示全部楼层
看看!便宜就好了
回复 支持 反对

使用道具 举报

0

主题

844

帖子

2750

积分

vip会员

Rank: 1

积分
2750
发表于 2016-7-8 00:42:44 | 显示全部楼层
这个支持了呀,不错,顶顶帖拿拿钱
回复 支持 反对

使用道具 举报

0

主题

889

帖子

2942

积分

vip会员

Rank: 1

积分
2942
发表于 2016-7-12 02:58:28 来自手机 | 显示全部楼层
我知道楼主一向黑~~~~~
回复 支持 反对

使用道具 举报

0

主题

873

帖子

2843

积分

vip会员

Rank: 1

积分
2843
发表于 2016-7-12 23:15:34 来自手机 | 显示全部楼层
搬运工 辛苦了
回复 支持 反对

使用道具 举报

0

主题

808

帖子

2642

积分

vip会员

Rank: 1

积分
2642
发表于 2016-7-18 10:18:41 来自手机 | 显示全部楼层
我知道楼主一向黑~~~~~
回复 支持 反对

使用道具 举报

0

主题

875

帖子

2922

积分

vip会员

Rank: 1

积分
2922
发表于 2016-7-18 23:25:29 来自手机 | 显示全部楼层
看一下,谢谢楼主分享
回复 支持 反对

使用道具 举报

0

主题

850

帖子

2807

积分

vip会员

Rank: 1

积分
2807
发表于 2016-7-21 06:51:19 来自手机 | 显示全部楼层
不错,我喜欢这个,看看多少金币哦
回复 支持 反对

使用道具 举报

*滑块验证:
您需要登录后才可以回帖 登录 | enginedx注册

本版积分规则

 
 



邮件留言:


 
返回顶部