Checking identical actor pointers

Hi
I know that it may sound stupid but I cant find out how to check if two pointers to two actors refer to same actor. Any ideas?

Have you tried just checking if they are equal? Unless I’ve massively misunderstood how the actors work, checking pointers will work. bool bAreSame = PtrA == PtrB

You could also just check the names, e.g.

return ActorPtrA->GetName() == ActorPtrB->GetName()

that would only check the pointers themselves, not what they point to.

What? If the pointers are the same then they point to the same thing? How could two pointers be the same put point to different things? Unless you had pointers to pointers, but that would be kind of mad.

Here is a scenario :
pointer A is in memory 1000 and points to 4000 in memory.
pointer B is in memory 2000 and points to 4000 in memory.
A!=B but *A=*B.

OK I don’t want to get in to an argument over this, but that isn’t how pointer equality works. If that were the case, when you compared two ints, they would need to be stored in the same location, not just having the same value. Pointer equality checks the value of the two pointers (e.g. in your example, would check that they both point to memory slot 4000) See: c++ - How to compare pointers? - Stack Overflow

AActor* ActorPtr1 = GetMyActor();
AActor* ActorPtr2 = GetMyActor();

if(ActorPtr1 == ActorPtr2)
{
   //These two actor ptrs point to the same actor!
}

#This works even across network functions

void Weee::Server_MyFunction_Implementation(ACharacter* ClientSaidToMakeThisCharacterJump)
{
   if(ClientSaidToMakeThisCharacterJump != nullptr)
  {
       //launches the correct proxy that was passed from client to server!
       ClientSaidToMakeThisCharacterJump->LaunchCharacter(...) 
  }
}

It works

I’ve been doing it for almost a year now in UE4 :slight_smile:

Rama

Oh, I think you are right :smiley: