A bool to check whether assets/landscape are fully loaded - unreal-engine4

A have a scene with a repeating runtime flow where I move a camera to anywhere in the world, spawn some models and capture a screenshot all in one frame. As its happening so quickly some materials, foilage, grass etc sometimes isn't ready in that single frame timeline. Is there a flag such as isLoading or isStreaming to check when all pending loading/streaming/LOD transitions have completed completed (Preferrably c++ rather than blueprints)?

Related

Unity Input System event triggered without input

Using the "new" Unity Input System.
I have a start scene with a menu and from there I can load the game scene where I have a TouchManager, the touch manager allows me to control the player and to visualize the force applied to the player.
To visualize the force I have a game object that starts disabled and with the touch manager I enable the visualizer only when there is touch input.
The issue is that at start of the game scene the touch visualizer is enabled, although after the first touch it starts working perfectly.
With debugging I see that the event that signals "touch" is fired (without touch) but the event that signals the release isn't.
Regarding the code there is nothing particularly relevant as far as I am aware, so I briefly explain: (Scripts by order of execution)
GameManager:
Awake() the game is set to pause;
Start() the game is set to "unpause";
TouchManager:
Pause(bool isPause) input events are subscribed and unsubscribed;
Move is the input that is causing the issue.
I tried to disable the visualizer but has to be on update since the event that enables it is triggered after start method and I dont know how/when the touch event is triggered, also I would like to fix the issue at the source instead of covering up.
Any ideas?

Does disabling graphics game objects prevent them from being affected by scripts?

I'm using frames (bounding boxes) to disable all game objects within an area when the player is not in that area. I want to know if parallax scripts will affect a disabled frame of objects. I don't want the parallax of background and foreground layers to be off when the player enters a new frame.
Slightly off-topic, but still relevant enough: I'm building the frames to be seemless transitions; is there a way to prevent parallax overlap at the transition point?
Scripts on disabled gameobjects do not recieve Update calls, as you've noticed. There are a few things you can do:
Not disable the entire gameobject when its outside the camera frame, instead only disable the renderer attached. This way your parralax script is still updated. Though its questionable if there are performance benefits to this, Unity does Frustrum culling by default.
Dont have individual parallax scripts, instead have one ParallaxManager in which you register all objects. This manager is never disabled, as an added benefit there is less overhead calling update.
Instead of update start some coroutine on another object, that isnt disabled. For example, in Parallax you can start a coroutine from the Camera gameobject. That way it keeps going, eventhough the parallax is disabled.
Try to calculate the right position in the OnEnable. That way you can still disable objects, and they appear at the right position when they are enabled again.

Unity Pattern For Moving Some Objects Between Scenes?

I'm looking for a pattern to transition between scenes, moving one instance of an object to the next scene and then later returning it to the prior scene, but without destroying the other objects that were in the prior scene. Here is the context:
When my game loads, it connects to my server to get the list of characters the player can control and instantiates them dynamically from a prefab.
The loading script moves each character game object to the main scene and then loads that scene.
The main scene now has the characters, which can be interacted with. So far, so good. One of the commands is to pick a specific character and send them on a task, which has its own task scene.
I can move that character to the task scene and move them back when the task is completed. However, the other characters who were not on the task and should not be in the task scene are now destroyed because the main scene was unloaded.
I'm looking for a pattern to accomplish this. Most of what I've read suggests using DontDestroyOnLoad, but this actually moves all characters into all scenes, which results in too many characters in the task scene. Another option might be to create a game object that holds all the character information, pass that between scenes and have logic in each scene to re-instantiate the appropriate character[s] in that scene. This feels like a lot of overhead since I have no other reason to be wiping and recreating them constantly. Perhaps a third option is to restructure my game so the task scene is just added to the main scene and shows up as some kind of overlay that blocks/captures input. This sounds messy and likely to have performance issues (targeting Android).
Does anyone have a good pattern for this?
with the scene manager you can create an empty scene, in this empty scene you put all of the objects you want to keep.
After you unload your first scene (not the one you create) and you load the next scene.
When your next scene is load you transfer all the object from the scene you create to the scene you just load.
PS : you have multiple scene load at the same time check this link for more informations :
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html
Turning comments into an answer.
Static variables can be accessed from any scene. Depending on the number of each class type you need, you can either instantiate a static class, or a static List/Array of class. Once you add your objects to it, you can access them from anywhere.
As long as this doesn't become a memory concern (thousands of large objects, eg), this should work well for your purposes (a few characters that need to persist throughout the game anyway).

Kudan in Unity: how to stop or reset markerless tracking?

I am creating an application with Kudan where a photograph (a 2D sprite) appears via markerless tracking. Based on the sample project I've successfully made adjustments so that the 2D plane is always perpendicular to the camera and placed on the screen in the position I want. Really wonderful!
But I am unable to figure out how to restart/reset the tracking via a script. I can always force the tracking to restart by blocking the camera or shaking the phone, but I want to do it via a button-- it is exactly the same behavior I've found described in the "ArbiTrack Basics" guide for Android and iOS, but am unable to reproduce it in Unity. To what script should I send a stop tracking command in order to get the tracking instance to restart (exactly the same effect as blocking the camera when running one of the sample Unity projects in Markerless Mode).
The situation is described here for Android coding: https://wiki.kudan.eu/ArbiTrack_Basics#Stopping_ArbiTrack
where it says to call these three things:
// Stop ArbiTrack
arbiTrack.stop();
// Display target node
arbiTrack.getTargetNode().setVisible(true);
//Change enum and label to reflect ArbiTrack state
arbitrack_state = ARBITRACK_STATE.ARBI_PLACEMENT;
I have found one way to do this-- though I'm not sure it's ideal.
Looking in the TrackingMethodMarkerless.cs script, it seems that the StopTracking() does not work-- it disables the updating of the tracking but doesn't actually disable the instance of detection. But taking a note from it, I added an if statement to the ProcessFrame() function:
//
if (disableMarkerless == false)
trackable.isDetected = _kudanTracker.ArbiTrackIsTracking ();
else
trackable.isDetected = false;
//
Now, changing the disableMarkerless bool operator disables the tracking.

UNITY: Synchronizing variables across a network

Ok, so I'm trying to implement networking for a school project. (Part of my team's final project)
It's supposed to operate on a turn-based system. IE, when a player is done, they hit "next turn" and they lose control, while the other player gains control.
So, to test my networking and get the basics going, I've made a little program that spawns a cube whenever a server is joined or created (so one cube for each player), and each player is able to move only their own cube.
So far, I can have the cubes moving around and their transforms are perfectly synced up on both instances of the game simultaneously, and each player can only control their own cube.
However, when I click "Next turn", the turn only changes on ONE of the instances.
According to this, it SHOULD be watching the turn change:
And this is my turncontrol code (It's a little sloppy for now until I find a hardcore way to set the code's player number depending on whether they're the host or client)
How the heck do I make sure that when I click "Next Turn", the turn changes in both instances, and how do I make sure that the cube's player number is dependent on whether they're the host or client?
That and I have the very strong suspicion that the assignment of a player's "player number" (IE, whether they're player 1 or 2) is being assigned locally (Not reflected across instances) as well, since each player can only move when the turn is set to 1 (Meaning that when both players spawn, they're both set to be player 1. :s)
Any assistance would be appreciated. Networking is completely new to me and I'm wigging out trying to wrap my head around it.