Referencing trouble. Illegal TEXT reference to a private object

I need to reference object in scene to modify its array from another object. I writed


public:
UPROPERTY(EditAnywhere)
AActor* Reference;

Now in “Details” tab i have window where i can select actor manually, but when i try to select ANY actor in scene I get this error:


Warning: Illegal TEXT reference to a private object in external package (StaticMeshActor /Game/MainScene.MainScene:PersistentLevel.Cube_2) from referencer (MyMyPlayerController_C /Engine/Transient.World_6:PersistentLevel.MyMyPlayerController_C_0).  Import failed...

What does this mistake mean at all? Wrong type? But the type of the object matches the expected type.

The actor im trying to reference is alredy exist in scene.

Has anybody solved this problem? I have the same problem.

You can’t set a hard reference to a level actor from an actor, your player controller, that doesn’t exist in the level yet. You need to use a soft reference through TSoftObjectPtr.


 
 TSoftObjectPtr<AActor> Reference; 

The above code should work for what you’re trying to do. However, you should reconsider setting references this way since the level actor only exists within that level. It would be better to pass the reference from your level blueprint to your game instance or game state, then retrieve that reference from your player controller.

8 Likes

Great!it work

thankyou, So much