How can i find objects and change properties in c++

hi , how can find object in c++ and change their properties , for example i have a PointLight1 on viewport and i want to change its visible = false / true .

pseude code:

object mypointlight = findobjectByName("pointlight1");
mypointlight.visible = true;

i want to do this in visual studio 2013 editor , pls help , if i do this  , i can do that another things this same way

how can we do these things :  findObject that placed on viewport, change their properties ,

This is an option. Maybe not the fastest one. But it gives you what you need :wink:



for (TActorIterator<YourClass> ActorItr(GetWorld()); ActorItr; ++ActorItr){
	if (ActorItr->GetName() == "yourName") ActorItr->SetActorHiddenInGame(true);
}


Ty , but its too slow if i have many object in viewport , its really easy in unity :((

Only cause it’s easy to use in Unity doesn’t mean it’s faster. For your “findObject” method there are several performance warnings.
Anyway, another option is to reference them in a UPROPERTY TArray. Then you can add your stuff in the editor into the array and handle stuff with it in c++;

You do realize that your Unity does the same thing, just encapsulated and hidden in a function call, right?

Jack Harb’s reply was correct, iterating through the list of objects is a way to go. Using the iterator mechanic you can limit the scope they’re searching through JUST LightActors. That way you can limit your search by a heavy amount.
Another proper way of coding would be to maintain a list of objects with many state-changes by yourself. Find your light actors at initialization and store a pointer to such an object in your own list or array.
Whenever you want to change the visibility, or any other state, just loop through your own small list.

best regards

The above posts are correct that it is better to refer to things by pointer than by name. If you do want to find an object by name though, you can use something like this, and it should be fairly quick because it uses the name->uobject hash table:


ALight* MyLight = FindObject<ALight>( Level, LightName );

You will need to specify a level, to prevent this finding the light in the edited level vs the played level.