[UE4]为Character创建插槽(socket)并绑定另一个actor

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/wag2765/article/details/84763460

为Character创建插槽(socket)并绑定另一个actor(比如一个武器),打开角色骨骼后找到要创建的位置,右键add socket


 

创建好以后修改socket的name和transform:


 

 

然后就可以用C++代码绑定武器到这个socket,通过参数SocketName指定:


if (!UnitSelector)
{
	UnitSelector = GetWorld()->SpawnActor<AActor>(UnitSelectorClass);
}
if (UnitSelector)
{
	UnitSelector->AttachRootComponentToActor(SelectedHero, FName("LeftHandSocket"));
}

 

 
如果不传递SocketName,绑定的位置不太确定,可以进游戏看效果再设置SpawnActor()函数的transform参数:

/**
	 * Spawn Actors with given transform and SpawnParameters
	 * 
	 * @param	Class					Class to Spawn
	 * @param	Location				Location To Spawn
	 * @param	Rotation				Rotation To Spawn
	 * @param	SpawnParameters			Spawn Parameters
	 *
	 * @return	Actor that just spawned
	 */
	AActor* SpawnActor( UClass* InClass, FVector const* Location=NULL, FRotator const* Rotation=NULL, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters() );
	/**
	 * Spawn Actors with given transform and SpawnParameters
	 * 
	 * @param	Class					Class to Spawn
	 * @param	Transform				World Transform to spawn on
	 * @param	SpawnParameters			Spawn Parameters
	 *
	 * @return	Actor that just spawned
	 */
	AActor* SpawnActor( UClass* Class, FTransform const* Transform, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters());

 

 

其他参考:

Attaching a weapon or object to hand or socket(蓝图操作)

https://www.youtube.com/watch?v=fyC57urfKtE

 

如果是为static mesh创建socket,直接在details面板的下面点击创建:


 

具体操作见官方文档:

https://docs.unrealengine.com/latest/INT/Engine/Content/Types/StaticMeshes/HowTo/Sockets/index.html

展开阅读全文

没有更多推荐了,返回首页