x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

[Closed] Run some logic only on client?

Hi!

How can I run a chunk of code only on the client? E.g. in the tick function in an actor I have some code that is completely unnecessary to run on the server but still needs on the client.

Thanks!

Product Version: Not Selected
Tags:
more ▼

asked Sep 12 '14 at 01:36 AM in C++ Programming

avatar image

undercover
843 123 111 138

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

The question has been closed Sep 14 '14 at 02:43 PM by undercover for the following reason:

The question is answered, right answer was accepted


1 answer: sort voted first

Answer

Wrap your tick code in this:

or to avoid checking every tick, start a timer function that runs with the required frequency only on clients, by using the above code to start the timer only on the client.

 if(GEngine->GetNetMode(GetWorld()) == NM_Client)
 {
     //code to only run on clients, will not run in single player / standalone
 }


YourGame.h must be using Engine.h instead of EngineMinimal.h to see GEngine (Epic please fix this, have to tell all my customers this)

More Info

Here's all the macros I use to do these tests, you could stick this in a .h somewhere or in YourGame.h

 #define ISDEDICATED (GEngine->GetNetMode(GetWorld()) == NM_DedicatedServer)
 #define ISLISTEN (GEngine->GetNetMode(GetWorld()) == NM_ListenServer)
 #define ISSTANDALONE (GEngine->GetNetMode(GetWorld()) == NM_Standalone)
 #define ISCLIENT (GEngine->GetNetMode(GetWorld()) == NM_Client)




more ▼

answered Sep 14 '14 at 02:43 AM

avatar image

Rama
10.6k 446 345 1088

avatar image undercover Sep 14 '14 at 02:43 PM

Thanks a lot!

avatar image Neros_ Feb 20 '15 at 02:57 AM

Is there a blueprint equivalent? I'm stuck on something very similar - https://answers.unrealengine.com/questions/174021/unwanted-replication.html

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question