#GameObject instantiation data

1 messages · Page 1 of 1 (latest)

grave horizon
#

but with those two you could probably keep track of scene objects data and compare to see what actually changed in a scene and its game objects

#

I'd like for the editor to prompt me with some sort of "fill in these required fields" or something so I can set the prefab up appropriately in the scene.
As for this one, it depends on the complexity of your needs

#

if your prefab is always gonna have the same type of components, it's fairly easy

#

but if you're gonna need a more flexible solution you will probably want to get what types of components the prefab has

#

and then tell your tool to prompt you to change whatever fields you want

#

i guess you could use SerializedProperty and the names of the fields for that, but it depends

fluid forge
#

Good suggestions here, thank yoU!

#

I will let you know what I come up with, but this is def putting me to the right spot. 🙂

grave horizon
#

if you're gonna register scene data that you'll need for the tool (number of gameobjects, names of gameobjects, parent/children relationships, etc)

#

you could use some of the Scene management events

#

and register all the data you need whenever you open a new scene

fluid forge
#

Maybe my use case will help you understand my goal here...

Under Spawns, I want the name of the GameObject to be the parent GameObject's Name + something unique. So when I change the parent GameObject, they all change too. I use this in UnitTesting to ensure uniqueness and no duplication.

#

Hence if i change the name of one object, i want it to cascade and change all these,

grave horizon
#

@fluid forge ah so you just want to automatically handle renaming when an object is reparented?

#

GameObjectUtility.EnsureUniqueNameForSibling can be useful for that

#

i thought you wanted to fill inspector field's data and stuff like that

#

you will still need to handle all the stuff I mentioned before, to check what GameObject changed its name and all that

fluid forge
#

i do want to fill inspector fields too, there are a couple moving pieces,

#

i have a bunch of prefab rooms. dropping them into the scene means i then have to rename the prefab to a unique name and then start hooking all the doors to the other rooms. it's an annoying long process of pasting, connecting, renaming, etc.

#

Thank you for the advice though! It will def help me.

grave horizon
#

ah I see

#

well, I'm not an expert on the topic so I can't offer more specific advice
but it should be enough to get you started

grave horizon
#

however if you are dealing with prefabs, they are already a way to already provide predetermined values to the object, so i don't know if prompting the user to fill some fields on the components would make sense

#

since with prefabs you would already have them filled, and if you need variations you can use the prefab workflow of Prefab Variants and all that

fluid forge
#

its not prompting the user, it's prompting me in making the game.

grave horizon
#

when I say the "user" i mean, you, or whatever designer will be instantiating those prefabs

#

I didn't mean the actual player of the game

#

feel free to share more context tho, since I may be missing something

#

but it feels like you're trying to walk around what the prefab system workflow offers

#

your initial question was:

I have a prefab and when I drop it into a scene, I'd like for the editor to prompt me with some sort of "fill in these required fields" or something so I can set the prefab up appropriately in the scene.

What setup requirements do you need to fulfill that the Prefab data itself can't define?

fluid forge
#

I'm making a metroidvania. I have prefabbed a lot of different rooms of different sizes.

When I drop them into my scene (which represents an "area" of my world), I then need to hook each of the doors up to the other rooms around it, connect it to the minimap, give it a unique name, give all of its doors names, etc. Doing that manually takes a lot of time.

grave horizon
#

ah i see now

#

it makes more sense in context

fluid forge
#

this is only a test of like 5 diff room shapes so far. look at all the possible connectins:

#

it aint gonna scale

fluid forge
#

Following up here, I made a button on the Inspector. I made pressing the button run a method that does a chunk of find/rename actions. It is close enough to do what i need.

I brought this script into my project: https://raw.githubusercontent.com/zaikman/UnityPublic/master/InspectorButton.cs

And then I use this on a MonoBehaviour:

public class InspectorButtonTest : MonoBehaviour
{
  [InspectorButton("OnButtonClicked")]
  public bool clickMe;

  private void OnButtonClicked()
  {
     Debug.Log("Clicked!");
  }
}
grave horizon
#

@fluid forge I prefer handling that sort of thing outside of runtime code

#

instead of a MonoBehaviour i'd use a MenuItem to add a menu when right clicking a GameObject

#

like that

#

or alternatively, something like this

#

I draw those menus with a middle click

#

to avoid clutter on the right click menus

#

it's a little bit more hassle to set up, but I like it better

#

here's how I do the middle click menus, in case you're interested