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

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:

主站蜘蛛池模板: 肥城市| 新河县| 会东县| 社旗县| 府谷县| 游戏| 安远县| 武川县| 泸定县| 兴城市| 利川市| 自贡市| 青川县| 靖西县| 什邡市| 夏邑县| 大悟县| 华阴市| 盐池县| 紫阳县| 湘乡市| 西藏| 无锡市| 海盐县| 景德镇市| 常德市| 宿迁市| 包头市| 永平县| 神农架林区| 潼南县| 定陶县| 平潭县| 于田县| 咸丰县| 屯门区| 石楼县| 莱州市| 永和县| 广东省| 称多县|