Unreal won't allow to select an actor reference

I have an EventHandler.h containing

public:
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    AActor* Sun = nullptr;

And an EventHandler_BP where if I try to assign something to the variable I get an error message saying:

Illegal TEXT reference to a private object in external package (Sun_BP_C /Game/Experimental.Experimental:PersistentLevel.Sun_BP) from referencer (EventHandler_BP_C /Game/EventHandler_BP.Default__EventHandler_BP_C).  Import failed...

Illegal TEXT reference to a private object in external package (Sun_BP_C /Game/Experimental.Experimental:PersistentLevel.Sun_BP) from referencer (EventHandler_BP_C /Engine/Transient.World_1:PersistentLevel.EventHandler_BP_C_5).  Import failed...

Bump, I have no idea what’s wrong.

Is your EventHandler a base UObject? So UEventHandler?

How have you instantiated your object on the BP side? Was it with a call/use of the “Construct Object from Class” node?

Have you verified that the object has been created successfully? Such as checking with one of the “IsValid” nodes? Then attaching a Print String and making sure it’s created OK?

(Apologies if this is stuff you’ve already covered - just trying to gather more information!)

Also, for some C++/RAII best practices, you’d be better off moving your property initialization into your Constructor, even making use of the constructor initialization list:

UEventHandler::UEventHandler()
 : Sun( nullptr )
{
}

Not entirely sure I’m understanding you with the last part.

You’re trying to access one of the Sun’s components? Or do you mean properties?

If the former (Component), is it a custom UActorComponent that you’ve created and added? Or just one that you’ve added via the “Add Component” button?

If the latter (Property), what details do you have in your UCLASS() Macro? When you say you can’t select anything, as in there’s nothing in the Class Defaults panel? Or it’s all greyed out?

Can you take some screenshots, might be easier to get to the bottom of your problem! :slight_smile:

EventHandler is an actor (AEventHandler) and the Sun_BP is already existing is the world, I’m just trying to access one of the sun’s component. I’m trying to select Sun_BP in the class defaults panel, but I can’t select anything, not just the Sun_BP.

It’s a component that I made that I’m trying to access, and for that I want to access the Sun_BP first.

244808-sun.png

OK great.

Where are you attempting to access the component? And how, for that matter?

You have your Sun_BP dragged into the scene, so what other area is attempting to access it? Are you doing it from the Level Blueprint? As this can get a reference to the actor. Or are you attempting to access the component, added in Blueprint, via C++?

I think I see what you’re trying to do.

Any reason you don’t want an ASun C++ class? This way, you can attach the component via C++, expose all of it to Blueprints to change any values, customize in a level - and you already have access to the objects/instances?

Anyway, what have you tried, in the Event Handler BP instance, in order to get the Sun?

Have you tried the “Get All Actors of Class” Node? It can be “expensive” in CPU costs, so use it sparringly and never in a Tick(). That’ll return to you your current instance of the Sun_BP, in the level. From there you can set the found instance to your Sun actor property, especially if you do this from within your Event Handler blueprint.

I didn’t attempt to access the component yet, because first I want to access the Sun_BP. The idea is that I have a Sun_BP with a DayNightCycle component that I made, and I also have an EventHandler.cpp where I try to access first the sun, than it’s component, and for that I created a variable in c++ (AActor* Sun), so I can attach the Sun_BP in the EventHandler_BP to that variable(AActor* Sun) and work with it in c++. I can access the Sun_BP from the level BP, but that’s not what I want.

Get All Actors of Class node works fine, but I don’t know if this is the best solution. I did make an ASun c++ class, I just didn’t reparent the Sun_BP yet, what do you suggest?

Okay, thank you very much for your help! :slight_smile:

Every tool can be useful in the right circumstances - Get All can be really useful when you’re initializing your level, for example.

Another option, in your Sun_BP, you could spawn an Event Handler actor instance - if it has no visuals, then the location/rotation isn’t important. Now you have an instance of your Event Handler object, you can pass the Sun instance as “self” (BPs equivalent to C++ keyword “this”).

My Suggestion: I would try to keep things contained within themselves. It’ll make things far easier to track down when debugging. So if you want to control the sun, it’s movement and various things, I’d recommend doing so within the ASun C++ class.

If you need your EventHandler to do stuff, you could always make use of Binders and/or Events, as you can pass almost anything via their parameters.

I had this happen to me right now, and the problem was that the two actors were in different sublevels.