SetWorldLocation function causing editor freeze

Currently have code that causes SetWorldLocation to freeze the editor. Not sure whats causing this issue.

	for (int i = 0; i < MAX_NUM; i++) {
	
		UOObject* obj= NewObject<UOObject>(this, UOObject::StaticClass());
		obj->id = obj_counter;
		obj->parent_id = objs[current_obj_index]->id;
		obj->box = generate_box(objs[current_obj_index]->bbox, i + 1);
		obj->RegisterComponent();
				
		if (IsValid(obj))
		   GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("obj is Valid"));   //<-- This executes
		else 
		   GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Yellow, TEXT("obj is NOT Valid, pending deletion"));

           obj->SetWorldLocation(FVector(obj->box.origin.X, obj->box.origin.Y, obj->box.origin.Z)); // <-- Problematic code
			
			 // ...
			 // ...
		}

UOObject in this context inherits from UBoxComponent. This code is in a function that is part of an actor class. The function, generate_box, generates valid numerical data and IsValid indicates the object is valid and is not pending for destruction. Attempted to use

AttachToComponent();
AttachToComponent(objs[current_obj_index]->id, FAttachmentTransformRules::KeepWorldTransform);

and even attempted:

AttachToComponent(RootComponent,  FAttachmentTransformRules::KeepWorldTransform); 

//Constructor code 
        root_component = CreateDefaultSubobject<USceneComponent>(TEXT("root"));
	RootComponent = root_component;

Both instances lead to a temporary freeze then offsets the world objects (which is surprising because KeepWorldTransform would imply world coordinates would be used)

Not sure whats causing this issue. Any ideas?

I’ve not checked but I’ll assume your UOObject derives from USceneComponent at some point.

  1. Make sure SetWorldLocation() is not preforming any collision checks. (bSweep parameter is false)

  2. SetWorldLocation() is preforming a global to local transformation each time which is probably unnecessary. Try with SetRelativeLocation instead.

  3. Try constructing the component at the correct position or moving it as “the first thing” to avoid recursive transformation when multiple Scene Components area attached to each other. (might not apply currently)

  4. Moving the whole iteration in asynchronous Editor Utility Task. It wont make it faster but it’ll prevent the freeze.

  5. Consider if you really need this to happen the way it does. If it happens rarely and is started manually, the freeze won’t bothered you anyway. (there is a Frozen reference somewhere in here :wink: ) What’s the value of MAX_NUM anyway?

Hope this helps. :innocent:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.