Search Unity

Question Cloned git repopsitory is missing all of the 3D objects in the scene.

Discussion in 'Editor & General Support' started by thenetimp, Aug 7, 2022.

  1. thenetimp

    thenetimp

    Joined:
    Sep 11, 2021
    Posts:
    12
    Hello,

    I created a project. I created a single 1x1x1 cube, and save the project. I initialized a git repository, adding this linked .gitignore file for unity. To ignore files that shouldn't be in the repository

    https://github.com/github/gitignore/blob/main/Unity.gitignore

    I then created a github repository, and linked the origin to the projects git repository and pushed the code to github.

    In a new directory I cloned the repository. I add it as a separate project in unity hub, and open it in Unity. The cube is gone. When I delete the cube, and do a git diff on the repository it tells me that the SampleScene.unity file has changed. I check github to see if that file exists. It does.

    The files in the repository, but why won't unity see the cube? What do I have to do to get Unity to play nice with Git and Github?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    There's a standard cascade of requirements to show any object: mesh, meshfilter, renderer, material, texture, scene setup, prefab, etc. Did you open both projects and compare?

    Sounds like you didn't add it to the repo!

    You typed a LOT of stuff up there but nowhere did you say what this 1x1x1 cube is.

    - a Unity cube? That's built in

    - an FBX? you gotta source control it

    - a Blender or Maya file? you have to source control it and ALL of the requirements for importing non-standard files apply

    - does it have a material?

    You should first ensure that you are using git properly.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    Here's how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally setting Unity up (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place. Digital storage is so unbelievably cheap today that you can buy gigabytes of flash drive storage for about the price of a cup of coffee. It's simply ridiculous not to back up.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  3. thenetimp

    thenetimp

    Joined:
    Sep 11, 2021
    Posts:
    12
    This is the first thing any unity tutorial teaches you is how to create a basic cube in the hierarchy. I was trying to keep it simple as a test as I have tried with more complex project and had similar results. "Create 3D object -> cube" The 3D cube is the test.

    I've been developing software for 25 years. I have been using Git for 15 of those years. I am well versed, in using git, and where it can or can not be stored and the various service that provide storage solutions. I have 2 computers. One is a desktop the other is a laptop, I want to be able to work on the same project either at home, or on the go, or simply sitting on the couch.

    This post (which you linked too)
    https://thoughtbot.com/blog/how-to-git-with-unity

    Is where I got the git ignore from, and followed to configure unity. Unity seems to already by default on new installs be configured as described as I saw nothing to change.

    i have double and triple checked. I have saved, and checked if things have needed to be committed, and there is no change in file on the main project directory. Nothing to commit. I push the main branch nothing to push. The cube is in the scene. When I go to the cloned project and do a git pull there is nothing to be pulled.

    When I do diff against the 2 repositories scene files they are the same
    diff Assets/Scenes/SampleScene.unity ../inventory-prototyping/Assets/Scenes/SampleScene.unity

    I use this file as the check because when I remove the cube and save and do a git status I get this

    Changes not staged for commit:
    (use "git add <file>..." to update what will be committed)
    (use "git restore <file>..." to discard changes in working directory)
    modified: Assets/Scenes/SampleScene.unity

    Something is missing from the process, and I find it hard to believe that it is this hard to setup basic version control in Unity.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    And did you open that same scene when you launched the clone project?

    It's trivial to do. Something is simply not as you think it is. Try more things! Try a capsule, try a sphere, make more scenes, make a prefab out of the cube, drag that into another scene. etc.
     
    AlexSmith2023 and englisni like this.
  5. thenetimp

    thenetimp

    Joined:
    Sep 11, 2021
    Posts:
    12
    OMG This is the dumbest thing ever, and will drive me crazy with every time I do this.

    I opened up the clone, and saw the scene I was in was called untitled. There is no "untitled" scene, it is SampleScene. Go into Assets->Scenes and double click on SampleScene and the cube shows up.

    Why?! Why does Unity not just open the ONLY scene in the project, why does it sit in this limbo state?

    The cube has been found...
     
  6. thenetimp

    thenetimp

    Joined:
    Sep 11, 2021
    Posts:
    12
    About 30 seconds before this post came in...
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Scenes are just documents, ways of organizing things. You can put everything in one scene if you like and turn it on and off, or you can organize your scenes in a nice meaningful way.

    The last document you opened is NOT saved anywhere you would source control. That would be silly: every time you changed scenes (documents) it would cause source control changes!! Instead that is saved in Library/

    I suppose for the same reason that Word, Excel, and just about every other document handling piece of software out there does it!

    If you want more on organizing things, I love using many small scenes all additively loaded together. Here's a blurb:

    Additive scene loading is one possible solution:

    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6630961
    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6754330

    https://forum.unity.com/threads/problem-with-canvas-ui-prefabs.1039075/#post-6726169

    A multi-scene loader thingy:

    https://pastebin.com/Vecczt5Q

    My typical Scene Loader:

    https://gist.github.com/kurtdekker/862da3bc22ee13aff61a7606ece6fdd3

    Other notes on additive scene loading:

    https://forum.unity.com/threads/removing-duplicates-on-load-scene.956568/#post-6233406

    Timing of scene loading:

    https://forum.unity.com/threads/fun...ject-in-the-second-scene.993141/#post-6449718

    Also, if something exists only in one scene, DO NOT MAKE A PREFAB out of it. It's a waste of time and needlessly splits your work between two files, the prefab and the scene, leading to many possible errors and edge cases.

    Two similar examples of checking if everything is ready to go:

    https://forum.unity.com/threads/daily-events-and-content-changes.1108202/#post-7143713

    https://forum.unity.com/threads/uni...on-before-other-scripts.1153739/#post-7401794
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Also, as you've been a software developer for a while, I strongly urge you to ABANDON ALL NOTION OF HOW YOU DO THINGS NOW and instead learn the Unity Way(tm).

    For one, you will NEVER use
    new
    to create a MonoBehaviour or a ScriptableObject.

    For two, you will NEVER implement constructors for Unity classes. That's not a thing.

    For three, you're welcome to inherit from Unity classes, but NONE of the methods are virtual or abstract, so you are setting yourself up for massive cognitive dissonance if you expect your base class's Unity messages to be called in your sub-class. That's not a thing that will ever happen unless you code it.

    For four, vast quantities of the Unity API surface are static / global, and for whatever reason, people unfamiliar with games get twitchy when they see this and then they want to wrap everything up in their own instance classes because they have some irrational hatred for globals.

    You will also do NOTHING with Unity except on the main thread. This means things like
    System.Timer
    callbacks and other network package delegates are completely off limits, unless you want to implement your own cross-thread delegate marshaling queue and appropriate locking mechanism. Instead, just use coroutines.

    These are just a few examples. They regularly trip up people with lots of experience. Don't be that person getting tripped up by well-understood things in Unity. Follow the Unity Way(tm)

    WHY? Why you ask? Why I'm glad you asked! It's because of this:

    Your code is not the application. Unity is the application. Your code is just a minor guest at the party:

    https://forum.unity.com/threads/res...-problem-when-using-ioc.1283879/#post-8140583

    Finally, this may prove very enlightening to you as you begin to do interesting things:

    Here is some timing diagram help:

    https://docs.unity3d.com/Manual/ExecutionOrder.html

    Two good discussions on Update() vs FixedUpdate() timing:

    https://jacksondunstan.com/articles/4824

    https://johnaustin.io/articles/2019/fix-your-unity-timestep
     
    Last edited: Aug 7, 2022
  9. thenetimp

    thenetimp

    Joined:
    Sep 11, 2021
    Posts:
    12
    Again this was only a test to figure out why my previous attempts at using Git on my larger project were failing. Now I know. I just needed that last bit of information of, hey you actually need to go a step further and open your scene after you clone. Would be nice if Unity opened up a scene if it was the only scene in the project by default.
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Not really.

    The moment you made a second scene in the project and repeated your process above, you'd be back in here posting the same exact thing because the scene would be Untitled.

    It would be actually more baffling because some indeterminate amount of time would have passed between the creation of the first scene and the second scene.
     
  11. thenetimp

    thenetimp

    Joined:
    Sep 11, 2021
    Posts:
    12
    Dude, your attitude sucks. The tone of your responses are rich with condescension. Once I find out how to block you I will.
     
  12. thenetimp

    thenetimp

    Joined:
    Sep 11, 2021
    Posts:
    12
    and ignored... goodbye..
     
  13. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I actually felt like your responses were condescending, FWIW. Specifically, the "I've been developing software for 25 years. I have been using Git for 15 of those years." I think that kind of attitude sucks. You came here asking for help from people who aren't paid to help you, they're just volunteers who enjoy assisting people who appreciate such assistance. His responses were spot on, even predicting the issue, which was that you didn't have the correct scene open. But he didn't agree with your opinion on something, in a stack where he has years of experience, and you have days.

    Basically, you're incredibly ignorant of how this program works. (That's okay. We all were, at one time.) Decades of experience in software in general doesn't instantly give you mastery over an unfamiliar IDE, so you don't need to tell people that anymore. (No one's impressed by that either, since a lot of people here are in the same boat.) So, kindly clean up your attitude. That's not how we do things in this forum.
     
    Kurt-Dekker likes this.
  14. thenetimp

    thenetimp

    Joined:
    Sep 11, 2021
    Posts:
    12
    I presented a scenario of my problem. He asked about what kind of cube. Ok sure, I can see where that may have been a problem, and then he said

    "You should first ensure that you are using git properly." Sure, yes I agree, but then went on this tirade.

    "Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there."

    Which was totally unnecessary and unrelated to the scenario. Giving me links to how to configure git for Unity? yes, but then a list of links that were related to git, but not really related to the question of why I couldn't see the cube. Only 2 of those links were related to making sure Unity was configured with git.

    Then the whole "forget everything you know about coding". This is not my first time using a 3rd party API to create something. I know the code I am creating is not the application, but rather a set of rules for the application to use for game play.

    The problem was that unity gives you an untitled scene that doesn't even exist in your project when you first open up a project that was brought in from git. I didn't notice that I wasn't in my SampleScene. Unity should instead do one of 3 things. If only one scene is present in a project, then open that scene, Open the top most scene, or don't open any scene, and don't put you in a non existent scene, instead giving you a blank area with some text telling you to open the scene. Yes you are right I am ignorant about some aspects of how Unity works, but I am also allowed an opinion on how I think it should work, and having someone tell me that no other application works that way and starts.

    If I open an existing word document that has been put in git, it will remember the last place someone was editing it at. If I open an excel spreadsheet that has been put into git and open it it will also remember what worksheet I was in. Now I can see scenarios where you don't want to remember where X person was in a Unity project if you have a team they may all be working in different scenes on different sections of code, and I bet if 3 developers were working on the same project and each save the project from different scenes when they opened it up again it would remember what scene they were in. The issue this weird state of user has never opened the project, where do I put them. They get put in a limbo scene that is confusing to someone who as you put it "is ignorant of how the program works".

    I don't put up with being talked down too. Not by my elders, not by my juniors, and especially from strangers on an internet forum. If you want to help someone take time to understand their problem before spouting unrelated non important information/links, and don't treat them like they're an idiot, cause that is how I felt I was being treated.
     
    Godflay likes this.