当前位置: 首页>>代码示例>>C++>>正文


C++ UObject::ConditionalPostLoadSubobjects方法代码示例

本文整理汇总了C++中UObject::ConditionalPostLoadSubobjects方法的典型用法代码示例。如果您正苦于以下问题:C++ UObject::ConditionalPostLoadSubobjects方法的具体用法?C++ UObject::ConditionalPostLoadSubobjects怎么用?C++ UObject::ConditionalPostLoadSubobjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UObject的用法示例。


在下文中一共展示了UObject::ConditionalPostLoadSubobjects方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetInstancedSubobject


//.........这里部分代码省略.........
            // search for the unique component instance that corresponds to this component template
            InstancedSubobject = GetDestinationObject(SourceSubobject);
            if ( InstancedSubobject == NULL )
            {
                if (bDoNotCreateNewInstance)
                {
                    InstancedSubobject = INVALID_OBJECT; // leave it unchanged
                }
                else
                {
                    // if the Outer for the component currently assigned to this property is the same as the object that we're instancing components for,
                    // the component does not need to be instanced; otherwise, there are two possiblities:
                    // 1. CurrentValue is a template and needs to be instanced
                    // 2. CurrentValue is an instanced component, in which case it should already be in InstanceGraph, UNLESS the component was created
                    //		at runtime (editinline export properties, for example).  If that is the case, CurrentValue will be an instance that is not linked
                    //		to the component template referenced by CurrentObject's archetype, and in this case, we also don't want to re-instance the component template

                    bool bIsRuntimeInstance = CurrentValue != SourceSubobject && CurrentValue->GetOuter() == CurrentObject;
                    if ( bDoNotCreateNewInstance || bIsRuntimeInstance )
                    {
                        InstancedSubobject = CurrentValue;
                    }
                    else
                    {
                        // If the component template is relevant in this context(client vs server vs editor), instance it.
                        const bool bShouldLoadForClient = SourceSubobject->NeedsLoadForClient();
                        const bool bShouldLoadForServer = SourceSubobject->NeedsLoadForServer();
                        const bool bShouldLoadForEditor = ( GIsEditor && ( bShouldLoadForClient || !CurrentObject->RootPackageHasAnyFlags(PKG_PlayInEditor) ) );

                        if ( ((GIsClient && bShouldLoadForClient) || (GIsServer && bShouldLoadForServer) || bShouldLoadForEditor) )
                        {
                            // this is the first time the instance corresponding to SourceSubobject has been requested

                            // get the object instance corresponding to the source component's Outer - this is the object that
                            // will be used as the Outer for the destination component
                            UObject* SubobjectOuter = GetDestinationObject(SourceSubobject->GetOuter());

                            checkf(SubobjectOuter, TEXT("No corresponding destination object found for '%s' while attempting to instance component '%s'"), *SourceSubobject->GetOuter()->GetFullName(), *SourceSubobject->GetFullName());

                            FName SubobjectName = SourceSubobject->GetFName();

                            // final archetype archetype will be the archetype of the template
                            UObject* FinalSubobjectArchetype = CurrentValue->GetArchetype();

                            // Don't seach for the existing subobjects on Blueprint-generated classes. What we'll find is a subobject
                            // created by the constructor which may not have all of its fields initialized to the correct value (which
                            // should be coming from a blueprint).
                            // NOTE: Since this function is called ONLY for Blueprint-generated classes, we may as well delete this 'if'.
                            if (!SubobjectOuter->GetClass()->HasAnyClassFlags(CLASS_CompiledFromBlueprint))
                            {
                                InstancedSubobject = StaticFindObjectFast(NULL, SubobjectOuter, SubobjectName);
                            }

                            if (InstancedSubobject && IsCreatingArchetype())
                            {
                                // since we are updating an archetype, this needs to reconstruct as that is the mechanism used to copy properties
                                // it will destroy the existing object and overwrite it
                                InstancedSubobject = NULL;
                            }

                            if (!InstancedSubobject)
                            {
                                // finally, create the component instance
                                InstancedSubobject = ConstructObject<UObject>(SourceSubobject->GetClass(), SubobjectOuter,
                                                     SubobjectName, SubobjectOuter->GetMaskedFlags(RF_PropagateToSubObjects), SourceSubobject,
                                                     true, this);
                            }
                        }
                    }
                }
            }
            else if ( IsLoadingObject() && InstancedSubobject->GetClass()->HasAnyClassFlags(CLASS_HasInstancedReference) )
            {
                /* When loading an object from disk, in some cases we have a component which has a reference to another component in DestinationObject which
                	wasn't serialized and hasn't yet been instanced.  For example, the PointLight class declared two component templates:

                		Begin DrawLightRadiusComponent0
                		End
                		Components.Add(DrawLightRadiusComponent0)

                		Begin MyPointLightComponent
                			SomeProperty=DrawLightRadiusComponent
                		End
                		LightComponent=MyPointLightComponent

                	The components array will be processed by UClass::InstanceSubobjectTemplates after the LightComponent property is processed.  If the instance
                	of DrawLightRadiusComponent0 that was created during the last session (i.e. when this object was saved) was identical to the component template
                	from the PointLight class's defaultproperties, and the instance of MyPointLightComponent was serialized, then the MyPointLightComponent instance will
                	exist in the InstanceGraph, but the instance of DrawLightRadiusComponent0 will not.  To handle this case and make sure that the SomeProperty variable of
                	the MyPointLightComponent instance is correctly set to the value of the DrawLightRadiusComponent0 instance that will be created as a result of calling
                	InstanceSubobjectTemplates on the PointLight actor from ConditionalPostLoad, we must call ConditionalPostLoad on each existing component instance that we
                	encounter, while we still have access to all of the component instances owned by the PointLight.
                */
                InstancedSubobject->ConditionalPostLoadSubobjects(this);
            }
        }
    }

    return InstancedSubobject;
}
开发者ID:kidaa,项目名称:UnrealEngineVR,代码行数:101,代码来源:CoreNative.cpp


注:本文中的UObject::ConditionalPostLoadSubobjects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。