Author Topic: Add Child to Grid via Instantiate  (Read 5868 times)

CoreWorkNode

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Add Child to Grid via Instantiate
« on: November 17, 2014, 11:24:13 AM »
So unfortunately I am using Photon Network as I have been for so long I do not wish to change.
However, When I PhotonNetwork.Instantiate "so other players can see the elements" I run into the snag.

  1. void AddPlayers(){
  2.                 GameObject PlayerCardPrefab = PhotonNetwork.Instantiate("PlayerCard", Vector3.zero, Quaternion.identity, 0);
  3.                 PlayerCardPrefab.transform.parent = GameObject.Find ("PlayersGrid").transform;
  4.                 GameObject.Find ("PlayersGrid").GetComponent<UIGrid>().Reposition();
  5.         }
  6.  

My "PlayerCard" makes my Grid act odd, by stretching it out of frame.When I reset the Transform component on my PlayerCard via IDE it goes into frame like it should.


As I am posting this Image I realized my, PlayerCard is being spawned with the size set at 300,300,300.

CoreWorkNode

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Add Child to Grid via Instantiate
« Reply #1 on: November 17, 2014, 11:29:27 AM »
For sure a problem with size. It only does this when I Parent the Grid to the PlayerCard. hmm.

This is working but it does not feel "politically correct"
  1. this.GetComponent<Transform>().localScale = new Vector3(1,1,1);
  2.  

« Last Edit: November 17, 2014, 11:36:06 AM by CoreWorkNode »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Add Child to Grid via Instantiate
« Reply #2 on: November 18, 2014, 05:12:58 AM »
NGUITools.AddChild resets the scale, among other things.

I don't know how Photon works here, but in TNet, all instantiation is not immediate. It's delayed so that it occurs on all clients. The fact that you're changing the parent right away like that suggests to me that it only happens on one client, but again -- I don't know how photon works here.

CoreWorkNode

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Add Child to Grid via Instantiate
« Reply #3 on: November 20, 2014, 09:32:34 AM »
Thanks for the Reply Aren.
Yeah, I Love NGUITools., Seems Photon does not play nice with NGUI gui elements sometimes. I may eat my words & switch to TNet, So my networking would get along with NGUI. I rather have NGUI than Photon. (lol)

Anyway thanks for the support!