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"

Why TArray is not replicating?

In my game, Character has a set of spells which I used a Tarray to store it and replicate it to all clients. And I did TArray replication just like the ShooterGame. But the TArray member only replicates the size of the array, excluding the spells.

Below is my C++ code:

alt text alt text alt text alt text

After spawning all the spell, in client side, I found that the SpellArray.Num() is correct, but SpellArray[i] == NULL. Help!! what's happening??

Product Version: Not Selected
Tags:
more ▼

asked Jan 15 '15 at 07:21 AM in C++ Programming

avatar image

Rambo_Wu
1 2 4 4

avatar image Rambo_Wu Jan 15 '15 at 07:35 AM

And After reading some similiar question on AnswerHud, I found someone solved it by "spell->SetReplicates(true);" after spawn the spell. But in my case, it still doesn't work!

avatar image Holybreath Nov 08 '16 at 11:48 AM

How about you make function that runs on server, and call it? Replication works from server to clients, so any variable change must run on server.

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

1 answer: sort voted first

try to put bReplicates = true; in initialize of ALabSpell, your should be in ALabSpell::ALabSpell(const class FObjectInitializer& PCIP) : Super(PCIP)

more ▼

answered Jan 15 '15 at 07:49 AM

avatar image

Duncan Dam
3.1k 121 50 164

avatar image Rambo_Wu Jan 15 '15 at 08:01 AM

Hey, Duncan. I did put "bReplicates = true; bReplicateInstigator = true;"

in the construction script of ALabSpell.

avatar image Duncan Dam Jan 15 '15 at 08:08 AM

ok, it should have work, we use same thing for our weapons, but we call AddUnique and then SetOwner for the weapon to the Pawn.

avatar image Rambo_Wu Jan 20 '15 at 05:34 AM

After setting SetOwner , it worked~

avatar image CChong Nov 08 '16 at 04:11 AM

Sorry to revive this old thread, but I'm facing a very similar issue - I'm spawning some Actors on the server, adding them to a replicated TArray, but I only end up with a (correctly sized) TArray full of NULLs on the client.

I've tried all the stuff mentioned here, including SetOwner(), bReplicates = true and actor->SetReplicates(true), but nothing works.

One difference, though, is that this TArray resides on my AGameState implementation (instead of, let's say, a replicated in-game character). Would this be an issue? Mind you, every other replicated variable in my AGameState replicates correctly - it's just this TArray that's misbehaving;

Thanks in advance for any help. Cheers!

avatar image CChong Nov 08 '16 at 06:04 AM

Solved it. What I forgot was that my replicated Actors in the TArray also have associated Blueprints. They started replicating correctly after I ticked the "Always Relevant" checkbox.

I guess this was needed because this TArray is really being used as a data container (spawned at origin and never moved, with the GameState as its owner instead of a Character/Pawn) and so was deemed as "not relevant" on the client.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

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

Answers to this question