官术网_书友最值得收藏!

Working With Object/Actor References

As with traditional programming, we need to avoid errors in our code that can occur from trying to access null variables. In Blueprints, there are a few ways in which we can make sure a variable is valid before using it:

  • Depending on the context, we may just need true or false (uncommon, but may be required in an if statement before a function call, for example).
  • The second method uses an IsValid function call with two outputs. Both of these can be found by typing valid in the search box.
  • The third method, which I prefer, is to use a Validated Get, which can be created by right-clicking on a normal Get node and clicking on Convert to Validated Get. This is essentially the same as the second method, but keeps the code cleaner:

Using a validated GET is the same as this snippet of code:

if ( MyActorReference != null )
{
// This is the Is Valid output.
}
else
{
// This is the Is Not Valid output.
}

The Is Valid output ensures that the MyActorReference variable isn't null, and you won't get any errors trying to access its variables and functions:

主站蜘蛛池模板: 石景山区| 东港市| 五家渠市| 六安市| 开远市| 临安市| 泗阳县| 寿宁县| 定陶县| 衡水市| 蓬莱市| 广汉市| 太康县| 开江县| 资溪县| 明光市| 南岸区| 桐柏县| 瓮安县| 惠州市| 河北区| 濮阳县| 当涂县| 临猗县| 内江市| 巴林左旗| 西安市| 开封县| 清水县| 潼南县| 昭通市| 巫溪县| 客服| 正宁县| 松江区| 遵义县| 凤山市| 哈巴河县| 滨海县| 巴塘县| 咸阳市|