Why does getting the position of and object return none?


This is inside a blueprint class called Portal 1, I have a similar class called portal 2, and both of them are placed in my level. However, when I try to retrieve the world location with the get world location node it gives me the error “accessed none trying to read the property”.

What I think this means is that the root component is none, which means the return value of the actor class is none. This makes no sense as when I press play “Event BeginPlay” should run and get the actor of the class Portal 2. I obtained the variable “Port 2” by doing the following:


I believe this is correct but I’m not sure. I am sure however portal 2 class is placed in the world.

This is my first time working with unreal engine and blueprint scripting. I probably am doing something obviously wrong but I don’t know what.

The first pic looks dodgy. How do you actually access the data? What fetches it and, most importantly, when are we doing this?


And no, the root component wouldn’t matter. You can do this instead:

image

The root is always there, if you do not put a specific component as root, you get the default one. And root location is always the same as actor location.


Also there are easier and more natural ways to connect two actors that are placed in the level. What you’re doing is fine for experimenting but will get out of hand with more portals.

image

I mean, this would work:

But it’s unsafe. Wouldn’t rely on this, and it is what’s causing the issue here, most likely.

accessed none trying to read the property

Would be nice to see the actual message or the bigger picture…

This is the entire error message “Blueprint Runtime Error: “Accessed None trying to read property CallFunc_GetActorOfClass_ReturnValue”.”.

The bigger picture is that I’m trying to make a portal system and a part of it is moving a capture component. The full blueprint is this:

If you absolutely must use it like this, then, at least, use a variable:

Do note that this will not work reliably a soon as you have 2 portals of the same class.


But my gut feeling tells me Get Actor does not actually get an actor at all. Try this:

See what it prints.

1 Like

I just tested this and it is not valid

You mentioned a better way to do this, could you explain to me how to do it or send me a link to somewhere?

This is my first ever project and I am unfamiliar with most features.

Could you briefly explain how the portals are supposed to work?

  • are they static - placed in the level?
  • does the player spawn them?
  • can they move?
  • how many are we going to have ?
  • does one portal always connect to another portal only or the connections are dynamic?

image

Asking as there will be as many ways as there are people. Would rather not push you in the wrong direction.

I’ll gladly explain. The portals in the end are going to be spawned from the player. In one instant there can only be two portals in the world, portal 1 and portal 2. These are separated into different blueprints for my convenience and should always connect. There will never be more than one portal 1 and more than one portal 2. Also they should be movable.

1 Like

But there can be zero portals?

There can be zero portals, but in the base case shown above (the one which gives me problems) both portals are placed.

GetActorOfClass can’t return None if there’s an actor in the level of that class. Are you sure that you’re calling it when an actor of that class exists?

It is placed in my level, I dragged it and dropt it from the content drawer in the level so it should exist

As mentioned before - there will be many ways to accomplish this. Here’s one:

  • Spawning and destroying actors is expensive so the player always has 2 portals:

The CA_Portal is a Child Actor Component that will automatically create an actor.

Instead of laboriously making and destroying portals, you can show / hide them instead. The portals live in the world space (Absolute Rotation and Location) so they can be placed anywhere in the world and will not follow the player.

  • the pure function traces in the direction where the actor is pointing:

We can now place those anywhere:

A portal can talk to the player like so:

There are better ways of doing this but it can be refactored later. Also, it would be much better if the portals were of the same class or, at least, inherited from the same class.


So if Portal 1 wanted to talk to Portal 2 via a direct reference:

This can be optimised, of course, but depends on what we need to do next. Perhaps there should be no logic in the portals themselves, the player could manage them since they know about both from the get-go…

1 Like

Sorry for the late reply, I’m implementing what you said. But when I move my character or rotate my view the placed portals move. I do not know if it changes things but I’m using UE5. The only difference I see in our code is the default structure of the first-person character:

Do you know how I could solve this issue?

I also just noticed that it only moves the portals when I move my view horizontally, and not when I move it vertically.

1 Like

It’s this purple thing:

The portals live in the world space (Absolute Rotation and Location) so they can be placed anywhere in the world and will not follow the player.

1 Like