Author Topic: TNManager.Create(go ...)  (Read 2584 times)

fredwen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
TNManager.Create(go ...)
« on: May 07, 2015, 05:25:59 AM »
I'm new to TNET,
TNManager.Create() accepts gameobject as the first parameter, but this gameobject must be in TNManger's list of objects.
I read the source code of TNManger, and found there is no public way to retrieve the objects list. If we cannot get the object in the list, then how can we pass it to Create()?  Do I have to use the Create(path, ...) instead?

It's will be very appreciated if anybody could paste some example code to show the correct way to use this Create(GameObject go, ...)


Ulnari

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: TNManager.Create(go ...)
« Reply #1 on: May 07, 2015, 06:29:44 AM »
The list in the TNManager has to be populated before you use TNManager.Create().

I populated the list via the Unity Inspector.

If you have a lot of different prefabs to instantiate, you could populate the list in code (haven't tried it, I read this is possible, though not best practice). TNManager.objects is public, you can assign your array of prefabs.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.Create(go ...)
« Reply #2 on: May 07, 2015, 09:48:22 PM »
You don't need to fill that list if your prefabs are in the Resources folder and you are instantiating them by name instead.

Simplest instantiation:

TNManager.Create("Some Prefab");

There are several versions of that function -- instantiating with position, rotation, scale, making it persistent (remains behind after player leaves)... you can even create custom creation functions to pass your own parameters to, as explained in the sticky post. http://www.tasharen.com/forum/index.php?topic=5416.0

ProfessionsQuest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: TNManager.Create(go ...)
« Reply #3 on: June 10, 2015, 10:54:24 AM »
Sorry for the stupid question but where is the "Resources" folder or the TNManager? I was following the "Making a game from scratch tutorial" but ran into an issue with the Player prefab. When I add the TNAutoJoin, it doesn't automatically add a TNManager script like it does in the video, so there's nowhere in the inspector to add the Player object. I tried to add the component myself, but TNManager doesn't show up in the dropdown.

Looking at later documentation, it looks like you highly suggest just adding the prefabs to the Resources folder but I also don't have a resources folder in my project. Where would I need to add one?

EDIT: Nevermind. I educated myself on Unity's Special Folders and just added a Resources folder where I wanted it to be. Then I changed TNAutoCreate.cs to take in string prefabName and call TNManager.Create (prefabName, transform.position, transform.rotation, persistent); and now it's no longer giving me an error.
« Last Edit: June 10, 2015, 11:26:04 AM by ProfessionsQuest »