Really Sporadic Unity Behavior? No Idea What is Causing it - macos

So I have Unity 5 for Mac, I'm on OS X 10.11, and I'm using MonoDevelop. Over the past week or so this glitch, bug, whatever it is has been getting more and more annoying to the point where it is now. Currently I have 1 script running and when I play my project 2 things happen:
The script doesn't run! I have it outputting a ton of things and it doesn't output anything or do what it is supposed to. I've tried refreshing the assets and everything, but after the first run, nothing
There is an even stranger thing happening. I have a RawImage used to display the webcam and a plane far far away from this RawImage. I am making a custom material for this plane that only has white and red. Nonetheless, this plane also shows the webcam. There is no code or property connecting the 2 whatsoever.
These 2 events always happen together. Now I have to restart Unity almost every run to fix this. I'll run it once, maybe twice, sometimes even 3 times and it will work perfectly fine then the next time it will do these things. Sometimes after running it another few times it will switch back. Sometimes I'll run it 10 or 15 times and it doesn't go back and I have to restart Unity. Has anyone run into any form of this very strange bug / glitch before?
[EDIT] Here is the code that might be causing the problem. This code is called in the Start method:
IEnumerator TakePicAndGetBestColor() {
yield return new WaitForSeconds (0.5f);
print ("here");
if (webcamTexture.width > 100) {
print ("HERE");
initFrame = webcamTexture.GetPixels ();
currentFrame = initFrame;
print ("waiting again");
if (initFrame [0].r >= 0.999f || initFrame [0].g >= 0.999f || initFrame [0].b >= 0.999f) {
print ("waiting");
yield return new WaitForSeconds (0.5f);
}
sorterThread = new Thread (() => TrackPhone.SortColors(initFrame));
print ("started");
sorterThread.Start ();
}
}
It prints up to "here," but doesn't print "HERE."
Here are some screenshots:
My setup:
The canvas when it is played:
The plane (looking down) when it is played (it SHOULDN'T look like this):
What it should look like:
I have found no reason why the plane should have the webcam texture. Nothing in script or in Unity.

Related

ive been trying to play an animation and the script is not working

`local button = game.StarterGui.ScreenGui.ImageButton
local AnimationController = script.Parent.AnimationController
local Animation = script.Animation
local animTrack = AnimationController:LoadAnimation(Animation)
local function PlayAnimation()
print("hi")
animTrack:Play()
end
button.MouseButton1Click:connect():Connect(PlayAnimation)`
, the print is not working so i assume its either the mousebutton1click is not working or the function is not connecting that is the first problem, the second is i have tried to start getting into animation and i could use some tips for animation of models that are moving cause of an event.
i tried changing some of the variables but that has not worked, i have tried writing it different, not working, tried chatGPT kinda helped, tried getting errors in the output with the print but that hasnt printed anything,i think cause of the connection to the gui button, that is all i can think of right now.
if you can help i would appreciate it.

How to get a death animation for my character in ActionScript 3 (Adobe Animate)

So basically I have two questions. I am also copying off this video from 2014: https://www.youtube.com/watch?v=w8JgpEjm8i8&t=2792s
Question 1
At the end of the video above the guys computer completely crashed and he wasnt able to show the end of how to setup a death animation for my player (link). So currently I have setup a movie clip of the death animation - just the playing spinning around - and put it in another movie clip called 'All Sprites' in which I have my other movie clips such as the different walking directions. So I have placed it in there, labelled it with "Link Death Frame". I then went back to the main script and added code so that once my player dies, the animation will play. Such as:
~
if(linkHealthBarMC.scaleX <= 0.01)
{
linkAlive = false;
}
trace(linkAlive);
if(linkAlive == false)
{
linkMC.gotoAndStop("Link Death Frame");
}
~
However, the issue comes in which the animation doesnt actually play, it just goes straight to the first frame and doesnt play. I have tested it and I know for sure that it gets stuck on the first frame and that something must be wrong with the animation as I tested it with another animation and it worked fine (once I met the requirements for the animation to play). So does anyone have any idea how I can fix this issue so that my character can play a death animation?
Question 2
How do I stop time? Like just completely freeze everything after my character is dead? Because at the moment I am just going to the first frame of the death animation and can still move and attack.
I'd assume this is on an EnterFrame loop. Then you would have two possible causes for this:
1.) You're loop is constantly checking if the 'linkAlive' if statement is false (which it is) and setting your Animation to the first frame. You can check this method by putting a Trace statement in your if statement and if the output window overflows, then that's your culprit.
2.) What you want is gotoAndPlay(-insert label here-)
Tho it is outside the scope of the question you have, I create a variable~Switch State machine to control states for me:
1.) Current State as a number (int, number, or uint)
2.) function with a switch statement (Switch is kind of a fancy if Statement)
3.) inside the cases are instructions
switch(current_state){
case 1:
linkMC.gotoAndPlay('death animation');
break;
}
if (current_state != 1){
-put movement code here-
}
This is close to what I use for my game. Just checking states or you can have a variable like the one above that explicitly checks for the death state and remove the ability to move. If you use a mouse (and I assume event listener) then you can remove the event listener for the mouse. If you use a solution like keyboard inputs then an if statement would be more what you are looking for.

Input.GetAxis("Mouse X") not working on some Windows configurations

public float GetAxis()
{
if (inputDevice == InputDevice.MouseKeyboard)
{
return Input.GetAxis(this.buttonName);
}
}
This code is working perfectly on my Windows 7 x64 PC. My Project Input settings are ordinal:
Input settings:
But I watched some videos on youtube where people playing my game. And they can't use mouse in it. Looks like Input.GetAxis("Mouse X") and Input.GetAxis("Mouse Y") has not returning proper values for them and they can't control camera in game.
Other input is working fine for them.
My Unity version is 5.6.0f3 and I can't upgrade to actual version because game's code is too complex.
How to troubleshot and fix it? I have not build for other platforms then windows x86 and x64.
Input object was constructed:
public GenericInput rotateCameraXInput = new GenericInput("Mouse X", "RightAnalogHorizontal");
To read delta mouse movement I am running this method in LateUpdate():
protected virtual void CameraInput()
{
if (tpCamera == null || cc.lockCamera)
return;
var Y = rotateCameraYInput.GetAxis();
var X = rotateCameraXInput.GetAxis();
}
I've come across this issue myself while using an RDP session or some kind of remote viewer such as TeamViewer. Mouse X and Mouse Y read the output directly from a device. If the device is not directly plugged into the machine that the player is being ran on then the inputs will not be properly retrieved. I'm not sure if this is the case for you, but this is the only instance I can think of these not being picked up.
Maybe you should add a bit of code that gets the mouse position each frame and outputs the difference, this would bypass the Mouse X/Y inputs anyways.
Update. It is not a bug. I've just missed something in my project.
I have a script to control the speed of mouse-controlled camera and PlayerPrefs variable to change it. And, in some conditions, that variable was set to 0. But for my case, it has already been set to registry and on my PC everything was working fine.
Maybe I need to delete this question, because it has not provided enough data.
I found this thread at unity forum There are some people who encountered the same issue on real Windows PC with different Unity versions and different mouse drivers.
This is an old Unity hardware compatibility bug. Looks like it can't be fixed other then upgrading Unity or using other Input system.

Unity, character selection screen on same PC by two players

The game I am trying to make include local multiplayer to play on same PC. I have done by making the different controllers in input manager and game work perfectly fine.
But now I am onto the part where I have to create a character selection screen for multiple player on same PC. I am beginner to the unity and learning right now. So I have no idea how to make it happen. Because when I tried to make it unity UI didn't able to take two input. At a time
I have also watched some of the threads in which people suggested to make your own eventsystem and button but I tried doing that somehow buttons are not taking any response they are not clickable. If anyone has seen those thread and that method is working for them, so please let me know how to.make it work
Or if someone has any other idea how to do please let me know
Thanks in advance
As far as I know, you CAN'T have more than one event system in the same scene.
So knowing that I'll suggest to change the...perspective about your game, here is something that can work:
You can't have more than one input on the same UI, but you can distinguish "keyboard" inputs. So let's guess the scenario that you have the screen divided in 2 parts, where left side is the Player 1 selection character, and can select between 2 characters, and right side is the Player 2 selection character, with the same number (or different, as you want!) of possible characters.
The pseudo code will be something like:
private Player m_player1;
private Player m_player2;
private CharacterSelection m_CharacterSelection_Player1;
private CharacterSelection m_CharacterSelection_Player2;
If (m_Player1.Input.GetKeyDown(KeyCode.A))
{
m_CharacterSelection_Player1.Left();
}
else if(m_Player1.Input.GetKeyDown(KeyCode.D)){
m_CharacterSelection_Player1.Right();
}
If (m_Player2.Input.GetKeyDown(KeyCode.LeftArrow))
{
m_CharacterSelection_Player2.Left();
}
else if(m_Player1.Input.GetKeyDown(KeyCode.RightArrow)){
m_CharacterSelection_Player2.Right();
}
Here is the visual representation about what I'm trying to tell you:

Adding, Removing, and Caching SKNodes

Background info:
I'm creating a SpriteKit 2D platform-style game with multiple "floors". When the user enters a "portal" he is transported to another floor (either one up or one down). If the user dies at a different floor from where the most recent spawnpoint is, he is transported back to the floor with the spawnpoint.
Problem: After upgrading to iOS8, this scenario causes the game to crash with an EXC_BAD_ACCESS exception/ error. Even after going through multiple tutorials on how to debug such errors, I cannot seem to find the problem.
So I'd really appreciate if someone could take a look at my code and tell me if they see a better way of doing what I'm doing, preferably without causing the game to freeze.
Game layout:
I have a custom class TileMapLayer which is based on the same class from Ray Wenderlich's book iOS Games By Tutorials. It is basically a custom SKNode class containing multiple 32x32p tiles, combined creating the background for my game.
I load the appropriate floor when the game begins, and then call to load another floor when my user goes up/down. In this scenario, I cache the current floor first in a NSDictionary so I can access it later if the user returns to this floor.
// Cache the current floor
[_allFloors setObject:_bgLayer forKey:[NSString stringWithFormat:#"floor_%tu", (unsigned)_currentFloor]];
// Remove the current floor
[_bgLayer removeFromParent];
// Get the cached (next) floor if it exists, if not create it
TileMapLayer *cachedFloor = [_allFloors objectForKey:[NSString stringWithFormat:#"floor_%tu", (unsigned)(_currentFloor + 1)]];
if (!cachedFloor) {
_bgLayer = [self createScenery:[NSNumber numberWithInteger:(_currentFloor + 1)]];
NSLog(#"creating new floor");
} else {
_bgLayer = cachedFloor;
NSLog(#"getting cached floor");
}
// Display the new floor
[_worldNode addChild:_bgLayer];
// Increment the floor number
_currentFloor++;
(I have a similar method for going down a floor as well).
This works perfectly, both before and after upgrading to iOS8.
When the user dies, he is transported back to the last spawnpoint. If the last spawnpoint is on a different floor, the floor also changes appropriately.
I call this custom SKAction on the ball itself as a part of an animation:
SKAction *changeFloor = [SKAction runBlock:^{
if (self.spawnFloor != _currentFloor) {
[_bgLayer removeFromParent];
_bgLayer = [_allFloors objectForKey:[NSString stringWithFormat:#"floor_%tu", (unsigned)self.spawnFloor]];
[_worldNode addChild:_bgLayer];
_currentFloor = self.spawnFloor;
NSLog(#"Made it here");
}
}];
As you can see there isn't much difference. The Made it here gets logged to the console, but the game freezes immediately after. The next method I call (to move the ball to the correct location) is not executed at all.
Just for fun I tried caching the _bgLayer before removing it from its parent like so:
if (self.spawnFloor != _currentFloor) {
[_allFloors setObject:_bgLayer forKey:[NSString stringWithFormat:#"floor_%tu", (unsigned)_currentFloor]];
...
And for some reason the game does not freeze when I do this. However, the floors end up being mixed as if the _bgLayer never was removed from its parent (note: the "old" tiles does no longer react to any physics-simulations, they're just in the background doing nothing).
I also tried [_bgLayer removeAllChildren] (removing the individual tiles) right after removing from the parent:
[_bgLayer removeFromParent];
[_bgLayer removeAllChildren];
But this causes the _bgLayer to be empty when I return to this floor after respawning. As if I removed all the nodes before I stored it in the dictionary. My guess is that the dictionary only references the location of the _bgLayer, not the content itself. So when I remove all the children on screen, I effectively remove all of them in the cache as well.
Wrapup:
I know this is a long question, and I'd like to say thank you if you made it this far. If you have any questions, please don't hesitate to ask them in the comments below.
Ultimately, what I'd like to know is this: How can I resolve my problem so the game doesn't freeze? What's the best practice for caching the floors without causing memory problems? What's the best practice for removing and adding the nodes on screen, and always referring to the current floor (the one that's on screen) as _bgLayer?
Again, thank you so much!
iOS8 seems to behave different when removing nodes inside blocks, as if you tried to do it on a background thread so sometimes it causes strange crashes. It might be a bug but until then I'd suggest two things:
1.- Mark the node to be removed inside the block but do it on the update: loop. You will not notice any difference.
2.- Make sure the removeFromParent happens in the main thread. But not sure this will fix the problem.
__strong typeof(_bgLayer) strongLayer = _bgLayer;
dispatch_async(dispatch_get_main_queue(), ^{
[strongLayer removeFromParent];
});

Resources