How to get the instance (in C++) of a blueprint that is instantiated from the editor

How can i do this??

I have:

class ADayCycle : public AActor

This class is the parent of a blueprint (skydome) that I place on the map.

I need to access some variables from code, defined in “ADayCycle.h”
For this i need the instance of the instantiated blueprint, right ?. how I can get it?

If you do code in ADayCycle with will work out of the box in skybox as it will inherent that code

As for outside of the class you need to do this

for (TActorIterator<ADayCycle> ActorItr(()); ActorItr; ++ActorItr)
{
	ActorItr->DoSonething();
}

I will grab all ADayCycle actors on the map (including related skybox) and cycle on each object found, the current cycled actor is available from iterator ActorItr like a pointer

thanks for the reply.
This answers my question.
However worries me use this loop in the case of many instances of a class in a level.
Any consideration about performance?

Depends what you doing to each object and how many objects there is, if you just switching varable to many objects it should be fast and theres no really other way to do it as engine would need to do loop anyway to do that task.

You can try to optimize it with “break;” and “continue;”

break; - will escape from the loop, good if you found object you need and dont want to check more objects, same as return; but return will escape from whole function.

continue; - will jump imiedietly to next object, next loop, good if you know that this object is not what you searching for and you want to check another one skiping pointless code operations on undesired object.

Those keywords actully works in any kind of loop in C++ :wink:

Hi guys,

What if instead of a blueprint i have a cpp that extends from Actor? When i debug it’s own constructor i can see that this code is being executed on the moment that i play the game but from (let’s say) an event, when i try to search it from MyCharacter, i only get a null collection of iterables. What am i missing?

Thanks.

Game world does not exist at construction, atleast not in actor class envraiment, you should override BeginPlay() insted.

Thanks for your response but the same happens though im trying to get the Actor from an event in MyCharacter class. What i meant with the constructor is that i debug and see clearly that an instance is created but then from any part of MyCharacter class i cant seem to get the actor. What could be causing this iterable to be null?

The actor class has no implementation whatsoever that could be causing problems :frowning:

Instance of what?

An instance of the Actor is being created when the game starts, i can see it’s instantiated because if i add a simple variable initialization on the constructor and debug, it stops on that breakpoint. Thing is, i can’t seem to find that instance on later functions with the iterator.

I have a class that can relate to DayCycle in this case. By doing the following: TActorIterator< ADayCycle > ActorItr =TActorIterator< ADayCycle >(());
I only get an empty iterator, meaning no class of type (ADayCycle) are found.

How do you initilize that actor? Show me the code

Hi, I never instantiate it directly by code. It happens that it’s the parent of a map level blueprint. But i found that my particular problem may be related to a problem in the editor. Somehow another developer can get this instance through the iterator while i can’t. I’m going to try to redo this actor - blueprint relation when i get the chance to see if the error persists.