查看: 904|回复: 11

[可视化蓝图脚本] 【Using Interfaces | Unreal Engine】

[复制链接]

1

主题

342

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

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



In this How To, we will set up a Blueprint Interface which will execute different scripts in multiple Blueprints when called.

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

In the Content/StarterContent/Props folder, Right-click on the SM_GlassWindow and choose Create Destructible Mesh.

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



We are going to turn this Static Mesh into a Destructible Mesh which we will break when shot.

Open the Destructible Mesh, then click Fracture Mesh and Save then close the Destructible Mesh Editor window.

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



Right-click on the SM_GlassWindow_DM asset, and under Asset Actions, select Create Blueprint Using This....

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



This will prompt you to enter a name and save location for the Blueprint (we used SM_GlassWindow_DM).

Right-click inside the Content Browser, then under Blueprints select Blueprint Interface.

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



This will again ask you to enter a name and save location for the Blueprint Interface (we used DM_Interface).

Inside the Blueprint Interface, name the existing Function IsDestructible and add the Inputs shown below by clicking New.

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



Above we have created three Inputs which we can use to pass variables between Blueprints that implement this Blueprint Interface. We have create two Float variables, one called Damage which will be used to pass an amount of damage to cause to the object we hit and the other Strength the amount of Impulse Strength to apply. Lastly, we added a Vector called HitLoc to hold the location in which the object was hit so that we may pass that information through as well.

Compile and Save then close the Blueprint Interface.

In the Content Browser open the SM_GlassWindow_DM Blueprint, then click the Class Settings option from the tool bar.

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



In the Details panel, click the Add button under Interfaces and add the DM_Interface.

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



This will implement the Blueprint Interface in this Blueprint, allowing us to access the functions within it.

Right-click in the graph and search for a  and select the Event Is Destructible Event.

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



Hold Control and drag in the Destructible component from the MyBlueprint window and create the script below.

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



Here, off the Destructible component we used Apply Damage and connected the damage, strength, location and direction requirements needed to apply damage to our glass window. The actual damage, strength and hit location information will be passed through the Blueprint Interface to this Blueprint from another Blueprint which we will do in a moment.

Compile and Save then close the Blueprint.

In the Content Browser under Content/StarterContent/Blueprints, open the Blueprint_CeilingLight Blueprint.

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



Using the Blueprint Interface, we will do something different when we shoot this light.

Add the DM_Interface through Class Settings then drag in the PointLight1 component and create the script below.

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



Here, when Event Is Destructible is called, we will first set the light to a green color. The second time it is called, we will set the intensity to 0 (turning off the light). Notice that we did not use the Damage, Strength or HitLoc information contained in the interface as it was not relevant to this Blueprint. By using a Blueprint Interface we can make a general function that is called in all Blueprints that implement that interface and function, and then determine what script is executed on each individual Blueprint.

Compile and Save then close the Blueprint.

Inside the Content Browser under Content/FirstPersonBP/Blueprints, open the FirstPersonProjectile Blueprint.

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



This Blueprint includes the script for the projectile that is spawned in-game when the player fires their weapon.

Add the DM_Interface through Class Settings then Right-click in the graph and add the IsDestructible(Message) node.

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



This will execute the function IsDestructible and all Blueprints that implement the interface and function will also execute.

If you do not see the node, un-check the Context Sensitive option in the upper-right corner of the context menu.

Off the False pin of the Branch connect the IsDestructible node and connect the Other and HitLocation pins.

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




Click for full image.

Above, we have added to the existing script that checks if the object that was hit is simulating physics. If it is not simulating physics, we call our IsDestructible function in our Blueprint Interface and apply 1000 damage and 100 strength to the target (which is gathered from the Event Hit node's Other pin where we also get the Hit Location and assign it to our HitLoc variable to pass through).

Compile and Save, then close the Blueprint.

Drag the SM_GlassWindow_DM and Blueprint_CeilingLight Blueprints into the level then click Play to play in the editor.

Shooting the glass will cause it to fracture and break apart.

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



Shooting the light once, will cause it to change to the color you specified in step 13.

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



Shooting the light a second time will cause it to turn off (also specified in step 13).

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



This is one example of using a Blueprint Interface to pass variables between Blueprints and call functions which execute different scripts in the Blueprints that implement the interface. For more information on working with Blueprint Interfaces and other forms of Blueprint communication, refer to the Related Topics section below.



   



   



      




   


      相关页面

  




       实现蓝图接口








      蓝图交互的用法








      蓝图用户指南




回复

使用道具 举报

0

主题

836

帖子

2732

积分

vip会员

Rank: 1

积分
2732
发表于 2016-7-2 19:57:33 | 显示全部楼层
这个多少金币啊。
回复 支持 反对

使用道具 举报

0

主题

863

帖子

2876

积分

vip会员

Rank: 1

积分
2876
发表于 2016-7-3 13:06:16 | 显示全部楼层
这个是什么呢,看看看
回复 支持 反对

使用道具 举报

0

主题

855

帖子

2840

积分

vip会员

Rank: 1

积分
2840
发表于 2016-7-4 07:57:03 | 显示全部楼层
有些买不起了,看看把
回复 支持 反对

使用道具 举报

0

主题

879

帖子

2890

积分

vip会员

Rank: 1

积分
2890
发表于 2016-7-8 00:42:44 | 显示全部楼层
好东西 好东西 好东西 好东西
回复 支持 反对

使用道具 举报

0

主题

846

帖子

2781

积分

vip会员

Rank: 1

积分
2781
发表于 2016-7-10 18:37:30 来自手机 | 显示全部楼层
谢谢楼主分享哈!
回复 支持 反对

使用道具 举报

0

主题

917

帖子

2942

积分

vip会员

Rank: 1

积分
2942
发表于 2016-7-12 02:58:28 来自手机 | 显示全部楼层
嗯,这个资源特别的好啊,赶紧下来收藏起来。
回复 支持 反对

使用道具 举报

0

主题

1305

帖子

4142

积分

vip会员

Rank: 1

积分
4142
发表于 2016-7-12 23:15:34 来自手机 | 显示全部楼层
都是好东西
回复 支持 反对

使用道具 举报

0

主题

890

帖子

2912

积分

vip会员

Rank: 1

积分
2912
发表于 2016-7-21 09:35:35 来自手机 | 显示全部楼层
这个必须可以有
回复 支持 反对

使用道具 举报

0

主题

881

帖子

2924

积分

vip会员

Rank: 1

积分
2924
发表于 2016-7-22 07:00:17 来自手机 | 显示全部楼层
一下这么多新发的好东东,谢谢分享
回复 支持 反对

使用道具 举报

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

本版积分规则

 
 



邮件留言:


 
返回顶部