本文整理汇总了C++中UActorComponent类的典型用法代码示例。如果您正苦于以下问题:C++ UActorComponent类的具体用法?C++ UActorComponent怎么用?C++ UActorComponent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UActorComponent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReattachComponents
void ReattachComponents(const TArray<FString>& Args)
{
if(Args.Num() != 1)
{
UE_LOG(LogConsoleResponse, Warning, TEXT("Reattach.Components: missing class name parameter"));
return;
}
UE_LOG(LogConsoleResponse, Display, TEXT("Reattach.Components:"));
UClass* Class=NULL;
if( ParseObject<UClass>( *Args[0], TEXT("CLASS="), Class, ANY_PACKAGE ) &&
Class->IsChildOf(UActorComponent::StaticClass()) )
{
for( FObjectIterator It(Class); It; ++It )
{
UActorComponent* ActorComponent = Cast<UActorComponent>(*It);
if( ActorComponent )
{
UE_LOG(LogConsoleResponse, Display, TEXT(" Component: %s"),
*ActorComponent->GetName());
FComponentReregisterContext Reregister(ActorComponent);
}
}
UE_LOG(LogConsoleResponse, Display, TEXT(""));
}
else
{
UE_LOG(LogConsoleResponse, Warning, TEXT("Reattach.Components: No objects with the class name '%s' found"), *Args[0]);
}
}
示例2: GenerateComboBoxIndexesRecurse
void SGraphPinLiveEditVar::GenerateComboBoxIndexes( TArray< TSharedPtr<int32> >& OutComboBoxIndexes )
{
if ( !NodeClass.IsValid() )
return;
UClass *InClass = Cast<UClass>(NodeClass.Get());
if ( InClass == NULL )
return;
GenerateComboBoxIndexesRecurse( InClass, FString(TEXT("")), OutComboBoxIndexes );
AActor *AsActor = Cast<AActor>(InClass->ClassDefaultObject);
if ( AsActor != NULL )
{
TArray<UActorComponent*> ActorComponents;
AsActor->GetComponents(ActorComponents);
for ( TArray<UActorComponent*>::TIterator ComponentIt(ActorComponents); ComponentIt; ++ComponentIt )
{
UActorComponent *Component = *ComponentIt;
check( Component != NULL );
FString ComponentName = Component->GetName() + FString(TEXT("."));
GenerateComboBoxIndexesRecurse( Component->GetClass(), ComponentName, OutComboBoxIndexes );
}
}
for (int32 i = 0; i < VariableNameList.Num(); ++i)
{
TSharedPtr<int32> EnumIdxPtr(new int32(i));
OutComboBoxIndexes.Add(EnumIdxPtr);
}
}
示例3: GetComponents
//* Destroys the constructed components.
void AActor::DestroyConstructedComponents()
{
// Remove all existing components
TInlineComponentArray<UActorComponent*> PreviouslyAttachedComponents;
GetComponents(PreviouslyAttachedComponents);
// We need the hierarchy to be torn down in attachment order, so do a quick sort
PreviouslyAttachedComponents.Remove(nullptr);
PreviouslyAttachedComponents.Sort([](UActorComponent& A, UActorComponent& B)
{
if (USceneComponent* BSC = Cast<USceneComponent>(&B))
{
if (BSC->AttachParent == &A)
{
return false;
}
}
return true;
});
for (UActorComponent* Component : PreviouslyAttachedComponents)
{
if (Component)
{
bool bDestroyComponent = false;
if (Component->IsCreatedByConstructionScript())
{
bDestroyComponent = true;
}
else
{
UActorComponent* OuterComponent = Component->GetTypedOuter<UActorComponent>();
while (OuterComponent)
{
if (OuterComponent->IsCreatedByConstructionScript())
{
bDestroyComponent = true;
break;
}
OuterComponent = OuterComponent->GetTypedOuter<UActorComponent>();
}
}
if (bDestroyComponent)
{
if (Component == RootComponent)
{
RootComponent = NULL;
}
Component->DestroyComponent();
// Rename component to avoid naming conflicts in the case where we rerun the SCS and name the new components the same way.
FName const NewBaseName( *(FString::Printf(TEXT("TRASH_%s"), *Component->GetClass()->GetName())) );
FName const NewObjectName = MakeUniqueObjectName(this, GetClass(), NewBaseName);
Component->Rename(*NewObjectName.ToString(), this, REN_ForceNoResetLoaders|REN_DontCreateRedirectors|REN_NonTransactional);
}
}
}
}
示例4: DrawComponentVisualizersHUD
void UUnrealEdEngine::DrawComponentVisualizersHUD(const FViewport* Viewport, const FSceneView* View, FCanvas* Canvas)
{
// Iterate over all selected actors
for (FSelectionIterator It(GetSelectedActorIterator()); It; ++It)
{
AActor* Actor = Cast<AActor>(*It);
if (Actor != NULL)
{
// Then iterate over components of that actor
TInlineComponentArray<UActorComponent*> Components;
Actor->GetComponents(Components);
for (int32 CompIdx = 0; CompIdx<Components.Num(); CompIdx++)
{
UActorComponent* Comp = Components[CompIdx];
if (Comp->IsRegistered())
{
// Try and find a visualizer
TSharedPtr<FComponentVisualizer> Visualizer = FindComponentVisualizer(Comp->GetClass());
if (Visualizer.IsValid())
{
Visualizer->DrawVisualizationHUD(Comp, Viewport, View, Canvas);
}
}
}
}
}
}
示例5: SetActorSelectionFlags
void UUnrealEdEngine::SetActorSelectionFlags (AActor* InActor)
{
TInlineComponentArray<UActorComponent*> Components;
InActor->GetComponents(Components);
//for every component in the actor
for(int32 ComponentIndex = 0; ComponentIndex < Components.Num(); ComponentIndex++)
{
UActorComponent* Component = Components[ComponentIndex];
if (Component->IsRegistered())
{
// If we have a 'child actor' component, want to update its visible selection state
UChildActorComponent* ChildActorComponent = Cast<UChildActorComponent>(Component);
if(ChildActorComponent != NULL && ChildActorComponent->ChildActor != NULL)
{
SetActorSelectionFlags(ChildActorComponent->ChildActor);
}
UPrimitiveComponent* PrimComponent = Cast<UPrimitiveComponent>(Component);
if(PrimComponent != NULL && PrimComponent->IsRegistered())
{
PrimComponent->PushSelectionToProxy();
}
UDecalComponent* DecalComponent = Cast<UDecalComponent>(Component);
if(DecalComponent != NULL)// && DecalComponent->IsRegistered())
{
DecalComponent->PushSelectionToProxy();
}
}
}
}
示例6: AttachComponentOfClass
UActorComponent* UActorBlueprintLibrary::AttachComponentOfClass(UObject* WorldContextObject, TSubclassOf<UActorComponent> ComponentClass, AActor* Owner, FName ComponentName, USceneComponent* AttachTo, FName SocketName)
{
if (!Owner)
{
return nullptr;
}
UActorComponent* Component = NewObject<UActorComponent>(Owner, *ComponentClass, ComponentName);
if (!Component)
{
return nullptr;
}
Component->RegisterComponent();
Component->OnComponentCreated();
USceneComponent* SceneComponent = Cast<USceneComponent>(Component);
if (SceneComponent)
{
SceneComponent->SetWorldLocation(Owner->GetActorLocation());
SceneComponent->SetWorldRotation(Owner->GetActorRotation());
USceneComponent* AttachToComponent = AttachTo ? AttachTo : Owner->GetRootComponent();
SceneComponent->AttachToComponent(AttachToComponent, FAttachmentTransformRules::KeepWorldTransform, SocketName);
}
return Component;
}
示例7: BindDynamicDelegates
void UComponentDelegateBinding::BindDynamicDelegates(AActor* InInstance) const
{
for(int32 BindIdx=0; BindIdx<ComponentDelegateBindings.Num(); BindIdx++)
{
const FBlueprintComponentDelegateBinding& Binding = ComponentDelegateBindings[BindIdx];
// Get the function we want to bind
UFunction* FunctionToBind = FindField<UFunction>(InInstance->GetClass(), Binding.FunctionNameToBind);
// Get the property that points to the component we want to assign to
UObjectProperty* ObjProp = FindField<UObjectProperty>(InInstance->GetClass(), Binding.ComponentPropertyName);
// If we have both of those..
if(ObjProp != NULL && FunctionToBind != NULL)
{
// ..see if there is actually a component assigned
UActorComponent* Component = Cast<UActorComponent>(ObjProp->GetObjectPropertyValue_InContainer(InInstance));
if(Component != NULL)
{
// If there is, find the delegate property on it
UMulticastDelegateProperty* DelegateProp = FindField<UMulticastDelegateProperty>(Component->GetClass(), Binding.DelegatePropertyName);
if(DelegateProp)
{
// Found that, finally bind function on the actor to this delegate
FMulticastScriptDelegate* TargetDelegate = DelegateProp->GetPropertyValuePtr_InContainer(Component);
FScriptDelegate Delegate;
Delegate.SetFunctionName(Binding.FunctionNameToBind);
Delegate.SetObject(InInstance);
TargetDelegate->AddUnique(Delegate);
}
}
}
}
}
示例8: GetObjectsOfClass
void FBlueprintCompileReinstancer::ReconstructOwnerInstances(TSubclassOf<UActorComponent> ComponentClass)
{
if (ComponentClass == nullptr)
{
return;
}
TArray<UObject*> ComponentInstances;
GetObjectsOfClass(ComponentClass, ComponentInstances, /*bIncludeDerivedClasses =*/false);
TSet<AActor*> OwnerInstances;
for (UObject* ComponentObj : ComponentInstances)
{
UActorComponent* Component = CastChecked<UActorComponent>(ComponentObj);
if (AActor* OwningActor = Component->GetOwner())
{
// we don't just rerun construction here, because we could end up
// doing it twice for the same actor (if it had multiple components
// of this kind), so we put that off as a secondary pass
OwnerInstances.Add(OwningActor);
}
}
for (AActor* ComponentOwner : OwnerInstances)
{
ComponentOwner->RerunConstructionScripts();
}
}
示例9: OnGetMaterialsForView
void FComponentMaterialCategory::OnGetMaterialsForView( IMaterialListBuilder& MaterialList )
{
const bool bAllowNullEntries = true;
// Iterate over every material on the actors
for( FMaterialIterator It( SelectedComponents ); It; ++It )
{
int32 MaterialIndex = It.GetMaterialIndex();
UActorComponent* CurrentComponent = It.GetComponent();
if( CurrentComponent )
{
UMaterialInterface* Material = It.GetMaterial();
AActor* Actor = CurrentComponent->GetOwner();
// Component materials can be replaced if the component supports material overrides
const bool bCanBeReplaced =
( CurrentComponent->IsA( UMeshComponent::StaticClass() ) ||
CurrentComponent->IsA( UTextRenderComponent::StaticClass() ) ||
CurrentComponent->IsA( ULandscapeComponent::StaticClass() ) );
// Add the material if we allow null materials to be added or we have a valid material
if( bAllowNullEntries || Material )
{
MaterialList.AddMaterial( MaterialIndex, Material, bCanBeReplaced );
}
}
}
}
示例10: ue_py_check
PyObject *py_ue_actor_destroy_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject");
PyObject *py_component;
if (!PyArg_ParseTuple(args, "O:actor_destroy_component", &py_component))
{
return NULL;
}
UActorComponent *component = ue_py_check_type<UActorComponent>(py_component);
if (!component)
return PyErr_Format(PyExc_Exception, "argument is not a UActorComponent");
#if ENGINE_MINOR_VERSION >= 17
component->DestroyComponent();
#else
actor->K2_DestroyComponent(component);
#endif
Py_INCREF(Py_None);
return Py_None;
}
示例11: GetWorld
FPreviewScene::~FPreviewScene()
{
// Stop any audio components playing in this scene
if( GEngine && GEngine->GetAudioDevice() )
{
GEngine->GetAudioDevice()->Flush( GetWorld(), false );
}
// Remove all the attached components
for( int32 ComponentIndex = 0; ComponentIndex < Components.Num(); ComponentIndex++ )
{
UActorComponent* Component = Components[ ComponentIndex ];
if (bForceAllUsedMipsResident)
{
// Remove the mip streaming override on the mesh to be removed
UMeshComponent* pMesh = Cast<UMeshComponent>(Component);
if (pMesh != NULL)
{
pMesh->SetTextureForceResidentFlag(false);
}
}
Component->UnregisterComponent();
}
PreviewWorld->CleanupWorld();
GEngine->DestroyWorldContext(GetWorld());
}
示例12: GetPreviewActor
void FSCSEditorViewportClient::Draw(const FSceneView* View, FPrimitiveDrawInterface* PDI)
{
FEditorViewportClient::Draw(View, PDI);
bool bHitTesting = PDI->IsHitTesting();
AActor* PreviewActor = GetPreviewActor();
if(PreviewActor)
{
if(GUnrealEd != NULL)
{
TArray<FSCSEditorTreeNodePtrType> SelectedNodes = BlueprintEditorPtr.Pin()->GetSelectedSCSEditorTreeNodes();
for (int32 SelectionIndex = 0; SelectionIndex < SelectedNodes.Num(); ++SelectionIndex)
{
FSCSEditorTreeNodePtrType SelectedNode = SelectedNodes[SelectionIndex];
UActorComponent* Comp = SelectedNode->FindComponentInstanceInActor(PreviewActor);
if(Comp != NULL && Comp->IsRegistered())
{
// Try and find a visualizer
TSharedPtr<FComponentVisualizer> Visualizer = GUnrealEd->FindComponentVisualizer(Comp->GetClass());
if (Visualizer.IsValid())
{
Visualizer->DrawVisualization(Comp, View, PDI);
}
}
}
}
}
}
示例13: GetClass
UActorComponent* AActor::AddComponent(FName TemplateName, bool bManualAttachment, const FTransform& RelativeTransform, const UObject* ComponentTemplateContext)
{
UActorComponent* Template = nullptr;
UBlueprintGeneratedClass* BlueprintGeneratedClass = Cast<UBlueprintGeneratedClass>((ComponentTemplateContext != nullptr) ? ComponentTemplateContext->GetClass() : GetClass());
while(BlueprintGeneratedClass != nullptr)
{
Template = BlueprintGeneratedClass->FindComponentTemplateByName(TemplateName);
if(nullptr != Template)
{
break;
}
BlueprintGeneratedClass = Cast<UBlueprintGeneratedClass>(BlueprintGeneratedClass->GetSuperClass());
}
bool bIsSceneComponent = false;
UActorComponent* NewActorComp = CreateComponentFromTemplate(Template);
if(NewActorComp != nullptr)
{
// Call function to notify component it has been created
NewActorComp->OnComponentCreated();
// The user has the option of doing attachment manually where they have complete control or via the automatic rule
// that the first component added becomes the root component, with subsequent components attached to the root.
USceneComponent* NewSceneComp = Cast<USceneComponent>(NewActorComp);
if(NewSceneComp != nullptr)
{
if (!bManualAttachment)
{
if (RootComponent == nullptr)
{
RootComponent = NewSceneComp;
}
else
{
NewSceneComp->AttachTo(RootComponent);
}
}
NewSceneComp->SetRelativeTransform(RelativeTransform);
bIsSceneComponent = true;
}
// Register component, which will create physics/rendering state, now component is in correct position
NewActorComp->RegisterComponent();
UWorld* World = GetWorld();
if (!bRunningUserConstructionScript && World && bIsSceneComponent)
{
UPrimitiveComponent* NewPrimitiveComponent = Cast<UPrimitiveComponent>(NewActorComp);
if (NewPrimitiveComponent && ACullDistanceVolume::CanBeAffectedByVolumes(NewPrimitiveComponent))
{
World->UpdateCullDistanceVolumes(this, NewPrimitiveComponent);
}
}
}
return NewActorComp;
}
示例14: FMessageLog
void AActor::CheckForErrors()
{
if ( GetClass()->HasAnyClassFlags(CLASS_Deprecated) )
{
FFormatNamedArguments Arguments;
Arguments.Add(TEXT("ActorName"), FText::FromString(GetName()));
FMessageLog("MapCheck").Warning()
->AddToken(FUObjectToken::Create(this))
->AddToken(FTextToken::Create(FText::Format(LOCTEXT( "MapCheck_Message_ActorIsObselete_Deprecated", "{ActorName} : Obsolete and must be removed! (Class is deprecated)" ), Arguments) ))
->AddToken(FMapErrorToken::Create(FMapErrors::ActorIsObselete));
return;
}
if ( GetClass()->HasAnyClassFlags(CLASS_Abstract) )
{
FFormatNamedArguments Arguments;
Arguments.Add(TEXT("ActorName"), FText::FromString(GetName()));
FMessageLog("MapCheck").Warning()
->AddToken(FUObjectToken::Create(this))
->AddToken(FTextToken::Create(FText::Format(LOCTEXT( "MapCheck_Message_ActorIsObselete_Abstract", "{ActorName} : Obsolete and must be removed! (Class is abstract)" ), Arguments) ))
->AddToken(FMapErrorToken::Create(FMapErrors::ActorIsObselete));
return;
}
UPrimitiveComponent* PrimComp = Cast<UPrimitiveComponent>(RootComponent);
if( PrimComp && (PrimComp->Mobility != EComponentMobility::Movable) && PrimComp->BodyInstance.bSimulatePhysics)
{
FFormatNamedArguments Arguments;
Arguments.Add(TEXT("ActorName"), FText::FromString(GetName()));
FMessageLog("MapCheck").Warning()
->AddToken(FUObjectToken::Create(this))
->AddToken(FTextToken::Create(FText::Format(LOCTEXT( "MapCheck_Message_StaticPhysNone", "{ActorName} : Static object with bSimulatePhysics set to true" ), Arguments) ))
->AddToken(FMapErrorToken::Create(FMapErrors::StaticPhysNone));
}
if( RootComponent && FMath::IsNearlyZero( GetRootComponent()->RelativeScale3D.X * GetRootComponent()->RelativeScale3D.Y * GetRootComponent()->RelativeScale3D.Z ) )
{
FFormatNamedArguments Arguments;
Arguments.Add(TEXT("ActorName"), FText::FromString(GetName()));
FMessageLog("MapCheck").Error()
->AddToken(FUObjectToken::Create(this))
->AddToken(FTextToken::Create(FText::Format(LOCTEXT( "MapCheck_Message_InvalidDrawscale", "{ActorName} : Invalid DrawScale/DrawScale3D" ), Arguments) ))
->AddToken(FMapErrorToken::Create(FMapErrors::InvalidDrawscale));
}
// Route error checking to components.
TInlineComponentArray<UActorComponent*> Components;
GetComponents(Components);
for ( int32 ComponentIndex = 0 ; ComponentIndex < Components.Num() ; ++ComponentIndex )
{
UActorComponent* ActorComponent = Components[ ComponentIndex ];
if (ActorComponent->IsRegistered())
{
ActorComponent->CheckForErrors();
}
}
}
示例15: check
UActorComponent* FComponentEditorUtils::DuplicateComponent(UActorComponent* TemplateComponent)
{
check(TemplateComponent);
UActorComponent* NewCloneComponent = nullptr;
AActor* Actor = TemplateComponent->GetOwner();
if (!TemplateComponent->IsEditorOnly() && Actor)
{
Actor->Modify();
UClass* ComponentClass = TemplateComponent->GetClass();
FName NewComponentName = *FComponentEditorUtils::GenerateValidVariableName(ComponentClass, Actor);
bool bKeepWorldLocationOnAttach = false;
const bool bTemplateTransactional = TemplateComponent->HasAllFlags(RF_Transactional);
TemplateComponent->SetFlags(RF_Transactional);
NewCloneComponent = DuplicateObject<UActorComponent>(TemplateComponent, Actor, NewComponentName );
if (!bTemplateTransactional)
{
TemplateComponent->ClearFlags(RF_Transactional);
}
USceneComponent* NewSceneComponent = Cast<USceneComponent>(NewCloneComponent);
if (NewSceneComponent)
{
// Ensure the clone doesn't think it has children
NewSceneComponent->AttachChildren.Empty();
// If the clone is a scene component without an attach parent, attach it to the root (can happen when duplicating the root component)
if (!NewSceneComponent->GetAttachParent())
{
USceneComponent* RootComponent = Actor->GetRootComponent();
check(RootComponent);
// ComponentToWorld is not a UPROPERTY, so make sure the clone has calculated it properly before attachment
NewSceneComponent->UpdateComponentToWorld();
NewSceneComponent->AttachTo(RootComponent, NAME_None, EAttachLocation::KeepWorldPosition);
}
}
NewCloneComponent->OnComponentCreated();
// Add to SerializedComponents array so it gets saved
Actor->AddInstanceComponent(NewCloneComponent);
// Register the new component
NewCloneComponent->RegisterComponent();
// Rerun construction scripts
Actor->RerunConstructionScripts();
}
return NewCloneComponent;
}