UE4 C++常用方法总结

本文深入探讨了UE4中的高级编程技巧,包括宏使用、鼠标控制、对象生成、组件初始化、定时器应用、日志记录、委托机制、游戏对象实例化等关键操作,为开发者提供了实用的代码示例。

1、常用宏

  UPROPERTY( )

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Zed|Components")
	UStaticMeshComponent* FinalLeftPlane;

 UFUNCTION()

BlueprintNativeEvent在ue4中是用来修饰UFUNCTION的,和BlueprintImplementableEvent有点类似,

BlueprintImplementableEvent用于实现C++调蓝图(声明在C++,实现在蓝图)

BlueprintNativeEvent除了实现C++调用蓝图外,同样会调用一个本地方法,本地方法为 声明的函数名+_Implementation

这样就可以实现一次调用,两个实现(c++实现,蓝图实现)

BlueprintNativeEvent还有一个比较有用的用法,是C++实现可以是virual,具体用法如下:

   //xx.h

	//C++实现,蓝图调用
	UFUNCTION(BlueprintCallable,Category="LowLevel")
    void FuncA(int a );

	//C++实现默认版本,蓝图可override实现
	UFUNCTION(BlueprintNativeEvent, Category="LowLevel")
	void FuncB();
	virtual void FuncB_Implementation(); //默认版本,这个要在C++中实现一下

	//C++不实现,蓝图实现.主要用于C++调用蓝图
	UFUNCTION(BlueprintImplementableEvent, Category="LowLevel")
	void Func();

引擎中很多地方就是用这种用法来实现派生类重写BlueprintNativeEvent函数的C++实现

2、程序中控制鼠标的显示

GetWorld()->GetFirstPlayerController()->bShowMouseCursor=true;

3、生成继承自Actor的对象

spawnActor = GetWorld()->SpawnActor<AActor1>(AActor1::StaticClass(),SpawnLocation);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值