Spawning Item OnWorldEnter Breaks Avatar

Options
Frizzled
edited October 2011 in Photon Server
I found some strange behavior in the MMODemo and I was wondering if someone could explain what was going on:

If you Spawn an item (say, a pet for the Avatar) in the OnWorldEntered Method after the Avatar's position is initialized (using engine.Avatar.MoveAbsolute), it breaks something and the Avatar's position is never passed to MmoActor (the Avatar keeps its default position from when it was created). But if you Spawn an Item before initializing the Avatar's position everything works fine.

You can also spawn Items after the OnWorldEntered event and that doesn't break anything. But if you want to do it in OnWorldEnter the Avatar has to be last.
//This doesn't work ... the Avatar's position will not be set
public void OnWorldEntered(Game game)
{

engine.Avatar.MoveAbsolute(**Avatar Starting Position**, **Avatar Starting Rotation**);
engine.Avatar.ResetPreviousPosition();

var item = new MyItem(Guid.NewGuid().ToString(), (byte)itemType, engine, name);
engine.AddItem(item);
item.Spawn(**Pet Starting Position**, **Pet Starting Rotation**, engine.Avatar.Color, false);

}
//This works ... the Avatar's position is set correctly
public void OnWorldEntered(Game game)
{

var item = new MyItem(Guid.NewGuid().ToString(), (byte)itemType, engine, name);
engine.AddItem(item);
item.Spawn(**Pet Starting Position**, **Pet Starting Rotation**, engine.Avatar.Color, false);

engine.Avatar.MoveAbsolute(**Avatar Starting Position**, **Avatar Starting Rotation**);
engine.Avatar.ResetPreviousPosition();

}

Anyone know why?

Comments

  • Boris
    Options
    AddItem sends operation SpawnItem, MoveAbsolute sends operation Move.
    Can you attach a debugger or configure logging to verify that both operations arrive?
  • With break-points:
    public void OnWorldEntered(Game game)
    {
    engine.Avatar.MoveAbsolute(**Avatar Starting Position**, **Avatar Starting Rotation**);
    ... item init
    item.Spawn(**Pet Starting Position**, **Pet Starting Rotation**, engine.Avatar.Color, false);
    }
    

    OperationMove break-point never hit
    OperationSpawnItem break-point hit

    public void OnWorldEntered(Game game)
    {
    ... item init
    item.Spawn(**Pet Starting Position**, **Pet Starting Rotation**, engine.Avatar.Color, false);
    
    engine.Avatar.MoveAbsolute(**Avatar Starting Position**, **Avatar Starting Rotation**);
    }
    

    OperationSpawnItem break-point hit
    OperationMove break-point hit



    For completeness:
    //Also works
    public void OnWorldEntered(Game game)
    {
    engine.Avatar.MoveAbsolute(**Avatar Starting Position**, **Avatar Starting Rotation**);
    //... item init
    //item.Spawn(**Pet Starting Position**, **Pet Starting Rotation**, engine.Avatar.Color, false);
    }
    

    OperationMove break-point hit


    Why would a Spawn call made after a MoveAbsolute call disrupt the Move Operation?
  • Boris
    Options
    It shouldn't.. can you try send the move operation reliable? Also please make sure that the move operation is actually sent. logging or something... want to make sure we are not missing something.
  • The client and server are on the same machine, the results are consistent - if you make a Spawn call before a MoveAbsolute for an Avatar in the OnWorldEnter method the Avatar never gets the Move Op. This could be replicated by taking the Photon Unity Island MMO demo and adding a Spawn call after the Avatar's MoveAbsolute in the OnWorldEnter method in MMOEngine.cs, the Avatar's starting position won't be set ... put the Spawn call before MoveAbsolute and everything will work fine.

    My goal is to move the Avatar spawn code to the server side, I ran into this strangeness along the way. I won't be using any code like this, but I thought I'd post it in-case someone else ran into a similar problem -or knew why this was happening so I could avoid a similar situation in the future. I am a little worried about running into wacky behavior trying to do something that seems relatively basic ... none the less thanks for the help.
  • Boris
    Options
    OK, thanks for reporting. We will try to reproduce.
  • Boris
    Options
    I need to know which version you use, is it Photon 3 RC4 ?
  • This was in photon/deploy/bin_Win32/version.txt

    Version: 3.0.3.734

    Is that what you need?
  • Boris
    Options
    actually the version of the photonsocketserver.dll would be more helpful. (right-click-->properties)
  • File version: 3.0.6.2188
  • Boris
    Options
    Thanks!