Some basic C++ questions

Hey guys, I’ve had actual fun doing C++, which surprised me so far. But I still have a couple of problems and there.

1: One of the questions I had is about Tick and void GetLifetimeReplicatedProps. How come Tick I have to define in my header file and use ‘override’ to be able to use it and for void GetLifetimeReplicatedProps I don’t have to?

2: Also, when do I have to type ‘class’ when using TSubClassOf<class SomeActor> compared to TSubClassOf<SomeActor>

3: Can I print something to the screen ONLY for a specific client? When using AddOnScreenDebug thingy on the client, it also prints it on the server.

4: I managed to get a TSubClassOf<> replicated and I really like this. I was wondering however, are there major differences between UClass and TSubClassOf? Should I always use TSubClassOf or are there times where its better to just use class?

5: Is it possible to replicate an actor to owning client and server bot NOT to any other clients?

Thank you in advance, I hope someone can help me out :slight_smile:

1: Because GetLifetimeReplicatedProps is automatically declared for you by Unreal if your class has any UPROPERTY(Replicated).

2: Because C++ doesn’t know what SomeActor is when it comes across it, so you have to tell it that the word SomeActor means a class called SomeActor. You don’t need to do this if the header for SomeActor is included already, because C++ then knows about it. Look up forward declaration to see how this works and why its useful.

3: When you use Play in Editor, all your players share the same instance of GEngine so they all print the AddOnScreenDebug, in standalone I don’t think this is true (but I could be wrong). Use APlayerController::ClientMessage to print a message to only one clients screen, but you need a reference to the player controller.

4: With UClass * you can reference any class at any time, with TSubclassOf<> you can restrict the types it can refer to, so in the editor only subclasses of that type show up. So prefer TSubclassOf<> when you know what kind of classes you want to store, and UClass * for when you need to be able to use any class.

5: I’m working on similar problems myself, but don’t have any robust solutions.

The Beej, thank you very much, that helps a lot :slight_smile: I hope we figure out question #5 soon. I found this: AActor::IsNetRelevantFor | Unreal Engine Documentation

Maybe something like that to make it not relevant for other actors except server and owner? Not sure exactly on the usage however, I come from c#, I’m still very clunky with c++