#💻┃code-beginner
1 messages · Page 320 of 1
👆
should be, try it and see
Hey! Is anyone able to help me with an issue I'm encountering?
My script works; however, it's doing something I don't want it to do. I've created a script that uses OnTriggerEnter to detect collisions with any mesh. It's supposed to check the material of the mesh and play an audio clip from an audio source. The audio clip should be different for each material. However, the problem I'm facing arises from my meshes having multiple materials. When I tap a mesh with multiple materials, instead of my script playing the audio clip set for the material "Tiles", it plays the material that's located at the top of the MeshRenderer's Materials list. I don't quite understand why it's doing this, and I'm also not sure how to fix this issue. If anyone can help me with this, I would greatly appreciate it.
Basically if thats too much to read (i yap too much) my script needs to check what material its touching correctly to play an audio clip based on that material but im having issues getting it to detect what material its touching... cus im not good at coding lol.
I would consider abandoning the material idea and adding a script that holds a simple enum
TryGetComponent to get that enum and play the sound based on that
But to answer your actual question, I don't know how to do that, sorry
😭
ill see what i can come up with
You're going to have a tough time pulling out the Material that corresponds to a the specific point on a mesh where a collision occurred (Not impossible, but tough). I think you would be better off breaking the meshes apart and reassembling them as prefabs. Then you can keep the code that works and only have one Material per mesh
maybe. i was gonna do that originally but i thought it might be a bit cleaner.
i just remembered my friends unity project uses what im looking for 😏
can enyone help me with my code
help with what, whats the code
im trying to make it so it teleports you to the next scene
Show the code
and whats the actual problem
And any errors or bugs
what is wrong with my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.sceneManagement;
public class NewBehaviourScript : MonoBehaviour
{
void onTriggerEnter(Collider other)
{
sceneManager.LoadScene(1);
}
}
Do you have two scenes?
onTriggerEnter
whats wrong with that
its just dosent work and i dont iknow what is wrong
Ah. See what gr4ss said
and whats wrong with using UnityEngine.sceneManagement;
anything in the console?
no
!ide ?
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
and sceneManager.LoadScene(1)
Lots wrong here. Definitely configure your ide. Also keep in mind that c# is case sensitive
Also, loading scene 1 would be the second scene (just to be clear)
i know that
also, this syntax error will definitely show up in the console
Good. Lots of other errors to fix
ok ill try and fix it
if you want to have full long term support, do !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
otherwise just fix the errors you have and encounter the same problem 100 times
ok thank you
I am fairly new to Unity I am taking C# classes rn and am trying to make a game, I followed taroDevs tutorial on a trajectory line and tried to tweak it to suit my golf game, however it needs optimization and I was wondering if anyone had any tips on how to optimize it
If I could send my project to have someone check it out that would be great I want to make sure I am structuring my project well.
i doubt anyone is going to do that
however people can look at your code
anyone got tips for programming an enemy battle ai? for a card battling game etc
using abilities
Learn everything you can about ScriptableObjects
i use them in my game, i mean like npc decision making
each card has 3 abilities to choose from in battle, and can swap between cards
well, depends how complicated you're making it but if you wanted to just make it pure rng
It's hard to give "Quick Tips" on AI approaches. I would probably use a filter based approach as that would give you the ability to configure different AI Players, but there's lots of ways to do it, and it's all VERY dependent on the granular details of your game.
i think i'm gonna calculate ability effectiveness based on situation then output the top 3 decisions and depending on the skill or level of enemy your fighting will determine it
like how in pokemon games some trainers are less smart than others
yeah definitely going to try this
I can image pokemon AI pretty straight forward
i agree it feels smooth
use best move, or throw the die
that'll likely be how my battle works but different style of battling
the battling is like the game Teeny Titans that is on mobile from the cartoon shows
but cards instead and other mechanics
after an hour of stealing. i think i may have stolen my friends code 🤦♂️ i am ashamed but as a legend once said
bibaty Bopaty your code is now my property ( he might kill me tmr 😭 )
He should've put the code in bank if he didn't want it to get stolen.
Nah he did but he gave me his Bank login and bank files 
Well, then he shouldn't complain about it being stolen.
ong!
My game can only manage upto 20 FPS? Can anyone tell me why?
u mean it depends on how your game is made sometimes a game may lag cus its in the unity editor and not a build.
but you could try using occlusion culling, Render distances,
you can use the built in Unity profile to find bottle necks to see what in the game causes lag.
you can try compressing your textures, the polygon count of your models can cause lag you can try reducing them
you can try Batch Rendering
and static batching
idk theres alot you can do but its hard to just determent the issue thats causing you lag.
It's hard to know you will have to run some tests most likely
So the number of trigs and verts arent abnormal right? This is all new to me so
Ok thanks! I'll see what i can do
same 😭
Hope you manage to figure it out
Open the profiler and look
Here is an overview for it
https://docs.unity3d.com/Manual/Profiler.html
Im seeing this
Set it to hierachy mode and look at what is taking the most time
But yeah, lotta rendering time going on
You have a crazy amount of batches. And looking at the profiler graph, rendering seems to be taking quite a while.
The editor is taking a lot as well, though.
The verts and tris may or may not be a problem depending on what hardware you're targetting. I'm guessing your issue is the crazy number of batches and setpass calls.
I think you need to mark pretty much your whole scene "Static" and then use Baked GI
Static huh, ok will look into it
Ok let me have look thanks!
i have just begun using unity and i am having a hard time figuring out how to open this door via animation
I've been having a little issue with some box stuff. I made the code so that my character may not jump if he's holding the box, with the SetHoldingBox value. But for some reason, even when he's just standing right next to the box (That has two Box Collision 2Ds for both hitbox and for pulling the box), the character is not allowed to jump, even if he is not grabbing the box. Any clues on how I could fix this?
hey can anyone help me with a code?
im doing a school proyect and my code doesnt work, basicly i need unity to get a int information from one scene to another, but it isnt working
im doing with GetInt
save a puntuation for a GameOver Screen
Static Variables/ Static class
Or a singleton
is what I would do, depending on what fits your need, but im no expert by any means
public int m_iTableID
{
get
{
return tableid;
}
set
{
tableid = value;
this.gameObject.name = value.ToString();
}
}```
will this property by itself have big problems? because i just found out a stack overflow error that blows up the whole editor
i can send you the code? maybe i write it worng
Sure, post it here
i dont see thing thats causing stack overflow
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System;
public class GetValue : MonoBehaviour
{
string Puntuacion = "Puntuacion";
public int CurrentScore { get; set; }
public void Awake ()
{
CurrentScore = PlayerPrefs.GetInt(Puntuacion);
}
public void SetScore(int score)
{
PlayerPrefs.SetInt(Puntuacion, score);
}
}```
Thats for getting the information
put the code in three `
3 before and 3 after
and add c# after the first three `
for proper formatting
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System;
public class GetValue : MonoBehaviour
{
string Puntuacion = "Puntuacion";
public int CurrentScore { get; set; }
public void Awake ()
{
CurrentScore = PlayerPrefs.GetInt(Puntuacion);
}
public void SetScore(int score)
{
PlayerPrefs.SetInt(Puntuacion, score);
}
}
thanks 😅
and i got this for getting information
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public TextMeshProUGUI textMesh;
void Start()
{
if (PlayerPrefs.HasKey("Puntuacion"))
{
int GetValue = PlayerPrefs.GetInt("Puntuacion");
}
}
}
it was the cs this.gameObject.name = value.ToString(); itself causing the overflow
i dont even know why tho
after i commented it out everything works perfectly fine
"this" made the overflow
its really about that keyword itself
I never used playerPrefs so i am not sure whats the issue, it looks right to me technically
One thing here is that you only get the score once in Awake() you never update it again, you onlyset the PlayerPrefs in SetScore() but the value CurrentScore is not being set when setting the score
Is that what your problem is?
I wouldnt use playerprefs for a score though
Just a static class I guess
i dont believe the this pointer can cause stack overflow but let me try
so change playerperfs to a static would be better?
make sure u save ur project first
Dont really know, I dont use playerPrefs so I cant tell you if its better or worse
But what exactly is the problem/ why is it not working?
public void SetScore(int score)
{
PlayerPrefs.SetInt(Puntuacion, score);
CurrentScore = score;
}
Add this line to Setscore
the code doesnt print any error, but when player dies, the puntuation in gameover screen stays in 0
oh
no stack overflow
try if it works with this
But you dont need the whole playerPrefs I think
stills the same
public static class Score
{
private static int _currentScore;
public static void SetScore(int score)
{
CurrentScore = score;
}
public static int GetScore()
{
return CurrentScore;
}
}
I wouldve probably done something like this
Im not at home so not sure if the syntax is correct
so i need to add another line? like C# void update ?
its ok, dont worry
so i change the player perfs to a static value in both codes
i think it would be easier
public class Score : MonoBehaviour
{
public TextMeshProUGUI textMesh;
void Start()
{
if (PlayerPrefs.HasKey("Puntuacion"))
{
int GetValue = PlayerPrefs.GetInt("Puntuacion");
}
}
}
What is this even supposed to do?
it doesnt do anything rightnow
no way
i should get the other code information for showing it in the other screen
public class Score : MonoBehaviour
{
public TextMeshProUGUI textMesh;
public int GetScore()
{
if (PlayerPrefs.HasKey("Puntuacion"))
{
return PlayerPrefs.GetInt("Puntuacion");
}
}
}
This at least does something
Now GetScore() returns the score
but the static class I posted makes more sense than splitting it in 2 classes
how you assign the value to m_iTableId
sorry 😅 , im really abd at this
theres 8 spots for assignment
RoomManager.Instance.myCurrentTableNumber = m_iTableID;```
mainly like this
definitely not about backup field tho
yoooooo its backup fields
aight problem solved thx lol
with this its says this error
public class Score : MonoBehaviour
{
public TextMeshProUGUI textMesh;
public int GetScore()
{
if (PlayerPrefs.HasKey("Puntuacion"))
{
return PlayerPrefs.GetInt("Puntuacion");
}
else
// Return whatever you want if the Key "Puntuacion" doesnt exist
{ return 0; }
}
}
add the else
If no key exists it still needs to return something
public static class Score
{
private static int _currentScore;
public static void SetScore(int score)
{
_currentScore = score;
}
public static int GetScore()
{
return _currentScore;
}
}
I would just do this
its much simpler and less error points, unless you absolutely need to use PlayerPrefs
its not necesary player perfs jaja
try this static class then
it should work already like this
you can add an extra method like
that should go to the code whos need to get the information, no?
public static void AddScore(int score)
{
_curentScore += score;
}
to add score instead of setting it
No
create a new file
Name it whatever you want
Score or something
ScoreHandler
if score is already taken
something like that
Remove the monobehaviour
make it static
Then you can use it from all scenes
It doesnt need to be attached to any gameObject
it cant actually
and then you can do ScoreHandler.GetScore() or ScoreHandler.SetScore() from anywhere
hey guys im trying to instantiate a prefab by using Resources.Load but it's giving me "The object you want to instantiate is null"
code please
GameObject bulletInstance = Instantiate(Resources.Load("/Assets/prefabs/projectile"), firePos.transform.position, Quaternion.Euler(0, 0, AngleDeg - 45f)) as GameObject;
To use Resources.Load. the prefab must be in the Resources folder
You should consider why you are using Resources.Load. There are certainly good reasons for it. But if you don't already have a Resources folder, it may be better not to use it.
I have my reasons
How can I immediately stop a gameobject from moving? I tried doing Rigidbody.velocity = Vector3.zero; but the object still slides a little before stopping
set isKinimatic to true
I'm guessing that changes it from Dynamic or Kinematic?
and would I still need to change the velocity to zero?
no, once it's kinematic it removes it from any physics calculations
I tried this but the object still slides a bit
I should specify that the object is actually the player, but when a trigger is enabled, the players movement script is disabled and the velocity set to zero
and now IsKinematic set to true
Sorry to comment on this, but you should avoid using Resources.Load at all costs
I heard the same
whats wrong with it
And I havent had a reason to use it yet anyways
If you want to spawn different prefabs its better to do public Prefab myPrefabBullet public Prefab myOtherPrefab and attach the prefab in the editor
the thing is, i dont want to attach it in the editor
The thing is Resouce.Load takes about 10-15x the amount of time and you load it from disk every time you instanciate
First of all this
2nd: You have to refer to everything in there by string which is prone to error
Yeah attaching the script to a gamemanager and then dropping the prefabs onto the fields in the Inspector is way better
3rd: I think the whole resources folder is packages in the build no matter if you use it or not and fully loaded into memory
which is bad if its alot
If you absolutely have to use it, dont use Resources.Load over and over again, cache it on startup or something
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Idk why it even exists, it has very specific reasons afaik, and unless you know why you need it, you shouldnt use it
Yeah I only used it once cause I thought it would be nice to not have to assign some things
But then I learned and knew better xD
is there other ways
This, but i see 0 reason why @polar grail couldnt just use the normal and more performant way.
yeah
to instantiate my prefab without having to assign it
I cant imagine having so many prefabs that you cant just assign them
Why
Explain why and if it makes sense i explain how
You shouldnt have so many that its too much work
if you do you are probably doing something wrong and should design your prefabs in a different/ better way
i guess so
It's useful for loading common prefabs. Just make sure to cache it and not call it more than is needed
Considering it was all inlined here I doubt it was needed
I have one PrefabManager that has my PrefabManager script that has like 200 prefabs attached
Lol
But if this is some common prefab then they should just load it beforehand
i guess i have to do that then
Also nice for loading things like JSON by the way, it definitely has its uses
Even if not you should just put it on the script that need it as an public Prefab Reference
Not with Resouces
cant stop me from using it :)
That's why I mention common prefabs
Cant stop you from making your game unplayable and choppy true
It's very nice to just Load some prefab that is used literally everywhere, and there is no shared instance possible
But we can advise against bad decisions
And even if it's 10x slower that whatever you specify, doing it just once doesn't make your app unplayable and choppy lol
im not making the next skyrim yo
Yes thats true, but loading it every shoot event, like it looked like is just no
There's definitely room for a better alternative with things, and I assume with the inlined code it's the same case, but this method definitely has use cases so it should not be shot down because it's super slow
No you're right, the code is horrible here
how do you justify your advice given the scene load time that will be impacted by having 200+ prefabs loaded when the script loads?
You should just not use Resouces.Load unless you really need it. As the other options are way more performant and dont require string literals (references by string)
The other one is even a longer load time ?
no it is not
uh oh!
Its known that Resources.Load is worlds slower then loading by Script Reference
Could even spin up a benchmark if i was home to tell you exactly how much slower
Last time i saw someone talk about it it was about 10x slower
There is just no need for it
Sure if you only load it here and there its not that bad, but then you also have the string references, which is also abysmal
Pretty sure the official docs say to avoid it aswell
It has basically only very rare usecases, most of the time referencing a prefab or something else on a script directly by dropping it in the Inspector is better.
you will find no one more anti string than me but, if I have 200+ prefabs and I only want to load 1 of them you can be damn sure I will use Resources.Load and I will be faster and more efficient than loading all 200+ in one go
I wouldnt say a prefab manager with 200 references is much better. And calling a game unplayable and choppy because it uses resources is silly
?!? Where does that even make sense
Then you only reference that one on the script
Where in the world is Resources.Load better there
My example with the 200 prefabs is cuz i need them all at runtime as its a shooter and every player could have a different prefab as player, outfit or gun, so i need them loaded at all times.
you are saying that is is better to have a script that prereferences all of the 200 prefabs rather than use Resources.Load to access 1 of them
No ? Never did that ?

I said doing 200 references is way better then 200 Resouces.Load
As in my example i needed 200 prefabs
you did
#💻┃code-beginner message
I don't use resource folder cause it's better, I use it cause im lazy
Sorry but are you confused ? Where am i saying that there ? There is 0 mention about any number.
Now please stop talking about it, im out.
if I was making games composed of hundreds of these high res 8k textures I'd probably build some decent bundles
Use it if you want to. We explained enough why it bad.
but I can't be bothered with the asset browser at times haha
You can explain why it is bad, but please do not suggest a prefab manager as an alternative when you have 200 stored in there.
There is literally no reason for such a script to exist
Litterally is, but if you cant read thats on you.
This
Ok by that same logic then there is a reason for resources to exist. Both reasons may be shitty though.
Resouces.Load would be fatally slower in the case of my script, that was the example for the speed.
Both of you just go in read half and then try to comment on it...
Use it if you want, im not here to try to defend why its better, if you dont believe me, then feel free to use it 
Are we done ? Good then i go back to work on my Multiplayer thats haunting me since days.
I mean, i also never needed a prefabmanager with 200 prefabs
That seems like alot
Whats the difference between all these prefabs?
I can look into a better way, but for now i have no other way i can think of how i can have the player have them all loaded, so if they encounter a player with that equipped that they see them correctly.
And I am not telling you to use resources either as an alternative. Lots of passive aggressive comments from you but it seems you dont even understand what I and others are telling you.
They are different weapons, different armour, helmets, jackets, etc pp
that is a damn good question, if you need 200 similar prefabs I would suggest there is something very wrong with your design
Its a multiplayer game ?
Yeah thats what im saying
Completly normal
No
prefabs are just pennies in terms of mem, it's the textures and audio that you'd want to be loading and deloading.
Yes it is, go start fortnite, valorant or splatoon and tell me how many different clothes and guns you find that people could have equipped
They wont be their own prefabs
No its often different models
Not just skins
My game is multiplayer with alot of different equipables/ races/ etc and i only have one player prefab
On there is a script that Syncs the IDs of each equipment between players
And the equip, weapons and co ? They are also prefabs
not for me
How do you spawn them then, directly the model ?
and the models too, yeah. But you can always manage a lot of the loading on the fly instead all at once
I have one basic weapon GameObject inside of my player
I change model/ textue depending on the Id of that equipment/ weapon
Yeah but i dont want a lot of loading or stutter when they encounter "new" objects they have not in memory
Thats why im preloading them, and prefabs so they have their animation scrips and other stuff already attached
I mean you load async it shouldnt be a problem
Same with the player, instead of switching out prefabs i just switch the visuals depending on selected gear/ race
On the same prefab
And all players perfectly see what everyone else has equipped
You don't want your whole game assets loaded at the same time. That's a recipe for disaster.
And what do i display while its loading ? Some black texture ?
That looks bad too
me?
well, for one I wouldn't load exactly when encountering that object
No. Generally. Mostly in reply to Elry.
ah ok
I'd be a bit smarter on your loading manager and have some idea of when and where to start loading your assets, even outside of a loading zone
But you do made me think about my approach with the 200 prefabs, maybe when the people are loading into the new server they get told what different objects are in the round and then they load that
Before the game starts
Just a note since you listed valorant above, there are times you can select an agent and nothing will appear for a few seconds except the loading animation.
True tho, but once ingame it all works and also the skins
Prolly use a approach like this
Load what the server says can appear ingame
But then i have to use Resouces.Load and thats kinda slow, but again when you are in the loading screens who cares about the 50-100ms more
What i dont know how to is that the main menu i wanted to do like fortnite where people could just join, then i would need to load the stuff while they are already appearing
But does that make a difference?
All things in resources are loaded into memory on startup anyways no?
Regardless of theyre ever actually used
Thats why its not recommended
I currently use 3gb ram when ingame and 2gb in lobby, thats with all 200 prefabs loaded
I didnt check my usage ever, but my game is very simple so i doubt ist uses alot
Would be interesting to see how/ if that changes when you use Resources.Load instead
So i should be good like rn and i dont have to load them when they are needed
Not much, if at all
Once they are loaded into memory it stays the same
But loading them is prolly more intense on Resouces.Load
yes, and you have stringreferences
Cuz you do string searches for files and then load them different
Didnt i say i wanted to leave and suffer with networking
lol
What are you using for networking?
@eternal needle @timber tide thanks for the headsup about the 200 prefabs, i will look into if its better to load them async when needed or all at once at start
Fishnet, defenetly easier then mirror, but still a pain
Ah okok
Im using mirror
Whats causing more problems is steam and the horrendous documentation for alot of things on steamworks
I found mirror horrendously bad to understand / use and while looking i found fishnet
So far really easy and it comes with neat stuff predone
Took a while but I understand alot now
The devs are very helpful in their discord and the docs are not bad
Also alot of examples etc there
I like that i dont have to do clientside prediction or lag compensation, that comes with FN
The lag thing only with Pro tho
Anyways i go back to suffering how to do scene stacking properly
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Is there any way to detect If an object has been activated
not talking about checking if it's active or not
I want to trigger an animation only when the object is activated
on enable
I am trying to get this to watch for *.uxml also, but i have not found the proper syntax to do that.
watcher = new FileSystemWatcher(dataPath, "*.cs")
//I have tried
watcher = new FileSystemWatcher(dataPath, "*.cs | *.uxml")
//and also
watcher = new FileSystemWatcher(dataPath, "*.cs; *.uxml")
i have even tried making a new watcher, but nothing i do seems to make things work. It Does work if i use *.cs or *.uxml independently though, so the surrounding code is doing its job
IDK why the hell the code blocks do not want to work for me, and i am done trying.
It's a function that I can't use on objects
what object?
I mean
actions.gun.OnEnable.SetTrigger("WeaponSwitch");```
It's not possible
I know
but I need it to be that way I showed above
As it's done in another gameobject's script
https://learn.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher.filter?view=net-8.0
'Note use of multiple filters is not supported'
then when another object is activated, call back to the object
ACK! Ok, thank you
tbh, I just use asterix . asterix and then filter myself
This is for a background recompiler, so when i press save in VS, is compiles over in Unity, without me having to click over to Unity and such. I do not know how to post filter a watcher for *.* though
string path = Path.Combine(project.path, "Assets");
watcher = new FileSystemWatcher(path);
watcher.InternalBufferSize = 32768; // 16384;
watcher.NotifyFilter = 0 //NotifyFilters.Attributes
//| NotifyFilters.CreationTime
| NotifyFilters.DirectoryName
| NotifyFilters.FileName
//| NotifyFilters.LastAccess
| NotifyFilters.LastWrite;
// | NotifyFilters.Security
// | NotifyFilters.Size;
watcher.Changed += OnChanged;
watcher.Created += OnCreated;
watcher.Deleted += OnDeleted;
watcher.Renamed += OnRenamed;
watcher.Error += OnError;
watcher.Filter = "*.*";
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
I'll give it a shot and see how it goes. Thanks
Hey guys, I'm trying to make movement for my rigidbody2D (the player) with inputs. I followed a guide on Youtube, but his script doesn't work at all for me
Here's the script:
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D body;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float xInput = Input.GetAxis("Horizontal")
float yInput = Input.GetAxis("Vertical")
body.velocity = new Vector2(xInput, yInput);
}
}```
and here's the video: https://www.youtube.com/watch?v=0-c3ErDzrh8
(reuploaded to fix an error in the edit of the previous version)
Heya Pals!
Welcome to a first in a series of video tutorials for Unity Development. We'll be covering all kinds of content in the series, so be sure to subscribe and check the playlist for future videos.
Music: Rifti Beats - Chocobo & Chill [Gamechops.com]
Chapters:
0:00 - Intr...
@languid spire Ok, for some reason i thought it was going to get strange on me when i made new assets, or created a new thing in the hierarchy, but that seems to be fine. Thanks again
Any errors in the log?
surely
cause you are missing some semicolons
Assets\PlayerMovement.cs(18,49): error CS1002: ; expected
yeah
I will try now
Seriouslly man, you need to pay attention to what you are doing
if it still doesnt work, my next 2 guesses from what the first error was will be that
- The script is not on the gameobject at all
- the rb is not assigned
I think it is on the game object, I created a new component in the inspector
It send me an error when I hit play:
UnassignedReferenceException: The variable body of PlayerMovement has not been assigned.
You probably need to assign the body variable of the PlayerMovement script in the inspector.
UnityEngine.Rigidbody2D.set_velocity (UnityEngine.Vector2 value) (at <39c25c7743074133aa8a65861b64bb60>:0)
PlayerMovement.Update () (at Assets/PlayerMovement.cs:19)
lol
gonna refer back to past me who saw the future here
But this is really basic stuff, you should probably go back to some basic programming tutorial in general to understand the basic principles and what the errors mean/how to use use/read them
I guess I should
but sometimes the errors are
almost
Plain english text that tells you what to do
Like
You probably need to assign the body variable of the PlayerMovement script in the inspector.
I know it's a problem about a missign variable in the inspector, that's what I'm trying to do
do you know how to set variables in the inspector?
I think yes, I created a variable called xInput of type float by adding a new component
no, that is declaring a variable for use in the inspector (maybe) that is not setting it's value
I can set the value in the inspector if I'm unserstanding correctly
I set the value to 4
then that is what you need to do here.
You have declared a variable 'body'
public Rigidbody2D body;
So now you need to give it a value in the inspector
you could set a string to "bananas" but im not sure how that will affect your playermovement
body is the name of your RigidBody2D component
its not assigned on the gameObject where the playerMovement script is
- Add a Rigidbody2D to the gameObject if it doesnt have one
- Drag that Component into the field body of PlayerMovement
or alternatively you can do
body = GetComponent<Rigidbody2d>();
in your start method
@languid spire i wanted to say sorry for the condesending way of talking to you earlier, i just had a bad example and i shouldnt have talked like that

Hi guys i have a question why when i add a camera to a gameobject the pivot position change like my object is in 0,0,0 and visualy on 0,0,0 and when i add my camera the position don't change but visualy not in 0,0,0
hello guys! So I just downloaded a death animation and created a transition from "any state" to it, with the requirement of a bool named "alive = false". To set the bool to false, I used a private void OnCollisionEnter2D(Collision2D collision and then a gameobjectcomparetag and the tag of the enemy to set it to false. Unfortunately this doesn't seem to work, as now my character repeats the die animation constantly without having touched the object but when he touches it it stops. Could this be because the if with comparetag enemy is in the same private void as another comparetag?
Show your code, the bool is already to false and you wanna set it to false ?
i have this here script that desnt give any errors but it doesnt call the debug nor does it instantiate anyhting. i was wondering if anyone could help
public Vector3 Tree;
void Start()
{
DropBranches();
}
IEnumerator DropBranches()
{
yield return new WaitForSeconds(Random.Range(1, 18));
ItemPrefab = Instantiate(ItemPrefab, Tree, Quaternion.identity);
Debug.Log("Dropped");
Start();
}```
i originally had it set to Update()
its a coroutine so you have to have to put in StartCoroutine(DropBranches());
My code was kinda long so I sent you a dm ^^
You can show only the OnCollisionEnter2D method
alright
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Platform")) { anim_grounded = true; grounded = true; // Man nuddar marken jumps = 2; // Refreshar mängden hopp du har när du väl nuddar marken } if (collision.gameObject.CompareTag("enemy")) { alive = false; } }
earlier I have a private bool for alive set to true and anim.SetBool("dying", alive);
could it just be an issue with me having two different comparetag ifs in the same method?
no its not the issue you can put 10 compareTag its same
What is the bool alive for ?
I use it as a condition for an animation transition
because if you want to change the bool in the animator you just need anim.SetBool("dying", alive);
so if you don't use the bool alive for an other check you can just put anim.SetBool("dying", alive); in you condition
anim.SetBool("dying", true or false);
like anim.SetBool("dying", true);
What does this error mean?? It keeps showing up and appearing and I can't do anything
This appears to be an internal Unity error judging by the underlying stacktrace
Try reloading your editor if this keeps popping up
okasy
Otherwise it's possible something does influence it but there's simply not a clear exception build in to explain it, so try finding something related to these nodes it mentiones
I need to assign the transform of my player to my prefab and cant open both in inspector at the same time, can anyone help me?
is Player a Scene gameobject?
yes
you cannot put scene objects into prefabs
You never need to. What are you trying to achieve?
i just made the player a prefab too it fixed
oh, no. I can see what comes next
did u see that i tell that it just takes the positions from the prefab and not actually from the Object in the scene?
im trying to download my game to my phone but it wont let me, how do I fix this?
and what makes you think that the transform of the player in the Scene will be the same as the Player pefab?
brain not braining
do you notice how it says 'See Console for Details' and yet the one thing you obscure is the console?
took the words out of my mouth xD
I am so tired of people that do not read messages
it must be easier to read one sentence rather than posting a screenshot here and writing a question no?
one step ahead would be to then google what you read before asking here
but thats like
very advanced already
but google isn't youtube and if it aint on youtube it don't exist
idk how but it is, the problem was that i was using Start() and Update() and now it works fine
so im even more stupid
than maybe you should think about the 'how' and actually learn something
Hi. I have a problem: I have a float "Hi", and from its values I need to get certain numbers: 300 = 0.1, 200 = 0.5, 100 = 1. This is just a rough example, I still need to take data between these numbers (250, 175. 63, etc.). What formula or function should I use for this?
is 300 0.1, or 0?
if it's 0.1, that's not a linear function so the question to ask would be what kind of curve do you want?
One option is to use an AnimationCurve.
is 0
Thanks
Is there a really simple way to get the direction from one transform to another transform?
to.position - from.position gets the offset aka difference
(to.position - from.position).normalized if you want a normalized direction vector
that gives me smth like this: (0.42, 0.15, -0.89) and what do i do with it now? like what number means what?
it's the direction vector you asked for
Why were you wanting the direction in the first place?
You can do whatever you'd like with it. Make an object face that direction. Fire a projectile in that direction
whatever
i dont know how to do math with vectors we havent had that in school yet, but i'll try to figure it out
If you explain exactly what you want to do, we could give a better answer.
You don't generally have to do any math
There must be some reason you asked for a direction vector
Those numbers are just the x, y, z parts of the vector
Vector is basically a distance but in 2/3 dimensions 😄
im in 2d why do i get a z
If you want an easy imagination
Unity is a 3D engine
it's always a 3D engine
makes sens
if you have a non-zero Z component it's because your objects are at different z positions
if i make it a Vector2 instead of a vector3 can i just forget about z?
that depends
it depends on when you make the conversion and whether you're normalizing or not
If you convert first and then normalize, then yes
You should probably just set the z positions to the same thing if you are doing 2d
if you don't normalize at all, then yes
if you are working in 2d, why are your objects different on the Z axis anyway, did you accidentially move one on Z?
(one object might be the camera!)
Ah of course.
its not
ok then generally they should all be at z = 0 but not always
but the second object was created by the camera so the z was messed up
i'll just subtract Vector3(0, 0, 10)
it works
you can set a position at creation in the Instantiate function
var newPosition = new Vector3(cameraTransform.x, cameraTransform.y, 0) would be enough to get the camera position with 0 on Z
var 😨
whats wrong with var?
They are hard to read
Not really 😄
also any IDE will annotate it for you, if the type isnt obvious in the first place
Changing the var by the actual type and simplifying the type assigned looks better
Vector3 newPosition = new(cameraTransform.x, cameraTransform.y, 0)
Sure it is, that was merely my opinion 😅
i have to update the position constantly anyways so adding 10 is easer for me
wait are you moving your player based on the camera position?
no
i want the player in my Game to be moved by getting attracted to a blackhole and i have to update the position of the blackhole constantly so it follows the mouse curser
and i want the strength of the attraction to decrees exponentially as the distance increases
and i want to unalive myself
The last piece of information was redundant
Oh, then what I would suggest is creating a plane that is on Z = 0, send a ray from camera to cursor position and get the intersection with the plane, put the black hole position on the intersection point
will automatically give you Z = 0 for your black hole position
So you want your black hole's position to the the same as cursor's and your the player to be dragged the this black hole?
So you want to move the player towards the cursor?
as for the attraction to the black hole, sounds like you need help with that? 😄
yes
but when the distance increases it gets exponentially slower
Create a hole GameObject and set its position to the position of the cursor in the world space
private void Update()
{
Vector2 mousePos = Input.mousePosition;
if (_mousePosPrev != mousePos)
{
blackHole.position = _mainCamera.ScreenToWorldPoint(Input.mousePosition);
_mousePosPrev = mousePos;
}
}
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Do you want actual physics or calculations to do that for you?
physics would be less predictable and harder to controll but might look better
https://hastebin.com/share/zefuziludi.csharp Any Idea why my cursor still shows on game window even after starting the game?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
In a build or editor?
editor
Try building, editor is funky with the mouse sometimes
All right thanks.
Then this should work
private void FixedUpdate()
{
Vector2 dir = blackHole.position - transform.position;
_rigidbody.AddForce(1 / Mathf.Pow(dir, 2) * blackHoleForce, ForceMode.Force);
}
i guess like Inverse-square law in real life but to a power of 1.5 so its not that strong
Never multiply by DeltaTime when adding force
I will try this first tho
No, this is a wrong statement.
The delta time is necessary here, as we're moving the rigidbody continuously
AddForce already factors in deltatime
Hey how could I do a wall such that some objects go through it but some no?
Unity has a collision matrix where you can set which layers collide with which
use layers to filter collisions https://docs.unity3d.com/Manual/LayerBasedCollision.html
Thanksss
I see, yes, that's right, the fixedDeltaTime shouldn't be used with the AddForce method inside of the FixedUpdate. I have corrected the code.
It shouldn't ever be used with any addforce mode in any location, nor with setting velocity
How do i access a boolen from a database
What's the error say
when i hover over the wiggly red line it tells me
'CharacterDataBase' does not contain a definition for 'IsColor' and no accessible extension method 'IsColor' accepting a first argument of type 'CharacterDataBase' could be found (are you missing a using directive or an assembly reference?)
Okay, so what is IsColor?
boolen i made in my database
that's not CharacterDataBase
That's not CharacterDataBase
So, where in this file is there anything named IsColor
hmm no
So then what are you trying to get IsColor from?
im confused
i followed a tutorial for this
why does this work with the sprite renderer and not a boolen
You didn't follow it correctly
i finished the tutorial and i want to make something of my own
You have a variable that holds a reference to a CharacterDataBase. You can see all the things that CharacterDataBase has in the code here. It doesn't have anything named IsColor so what are you actually trying to get
It doesn't
link it
CharacterDatabase doesn't have a sprite renderer either
It WOULD work with a boolean, if you actually had that boolean, which you do not
this is a code channel
Find the button that looks like this in your image editor of choice
In this unity tutorial, you'll be learning how to make a character and skin selection menu for your game.
You'll learn how to use scriptable objects to make a character database. Scriptable object is a data container that you can use to save large amounts of data.
Timestamps:
0:00 Intro
0:17 Character Selection UI Setup
1:32 Character Scripti...
how do i put it
Notice how at no point are they ever trying to read a sprite renderer from the CharacterDatabase
They are trying to get it from a Character
isnt this Character?
Yes
But you're not trying to get IsColor from that
You're trying to get it from this
You cannot tell what color a pair of shoes are by looking at the shoebox
Your variable characterDB is a shoebox full of Characters
The shoebox itself is not shoes
public bool MyBoolean
Same way as writing any variable.
What isn't
Compiler errors?
none
Show the code
any compile errors include the one you were trying to receive help with
Show your console
Hello guys, I'm trying to make a project following a Youtube video, however this video is dated. in the code it states csharp public override void OnActionReceived(float[] vectorAction) { if (vectorAction[0] == 1) { Thrust(); } } But since Im using the newer version I have to use ```csharp
public override void OnActionReceived(ActionBuffers actions)
{
}
Idk the difference but my guess is one new one was added
but i dont know how to make isColor in the database equal to IsColor in the character
Can someone help me with this code?
Why would you want to
Why does your database have an IsColor
so character manager can get it like the sprite
Why not just get it from the character
- !code
- You have to actually ask a question
!code 👇
also describe the issue you are experiencing with this code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
a boolen to check if you can change the sprites color
double kill
But why does the database have one
Get it from the character
Do you understand that a database is not the same as the things inside it
Do you want the IsColor boolean to belong to the Character or the Box the characters are stored in
i want each skin to have a boolen
which now it shows
Then don't put IsColor in the database. get it from the character
thank you
So, then why does your database have an IsColor boolean
What is the point of that
what value does that represent
i removed it
Imagine a big box. It contains a piece of paper with some information, and other boxes.
The other boxes also have information inside.
You are trying to look in the big box for information in the little boxes.
Just open the smaller box
ok i will try this out
Okay. Now that it's gone, if you want to get IsColor from a character, you need to actually do .IsColor on a character. Not the database. Look at how you're getting the sprite renderer
You are not getting it from CharacterDB
Super quick can you have 2 yield(s) in 1 coroutine?
Yes
It's giving me an invisible error when I try to do it
You can have as many as you want
you can have as many yields as you like
"Invisible error"?
what is an "invisible error"?
maybe just share your code and your error
In VisualStudio there is no errors but I can't drag it onto my objects in unity over a compile error or class issue (I took out the 2nd yield and it worked fine)
Look at your unity console
unity console is the source of truth for compile errors
Also double check that your class name matches your filename
maybe just share your code
whats the difference between OnCollisionEnter and OnTriggerEnter ?
I figured out I can search the debug statements and apparently my assignment to the dictionary isn't working
One of them detects whenever you've hit a solid collider. The other one detects whether you're inside a non-physical trigger area
ok, thanks
Is that key a Vector3 or Vector3Int? If it's a float vector, it might not actually be equal
How do I wait for a unity Animator animation to finish playing before executing some code?
I cannot seem to find a way to detect state to wait for that, the code keeps returning true that its not animating even when it is
check animator state, or you can do Animation Event
or maybe Exit state
private bool IsAnimationPlaying(string animName)
{
AnimatorStateInfo stateInfo = atlasAnimator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.IsName(animName))
{
if (!stateInfo.loop || (stateInfo.loop && stateInfo.normalizedTime % 1.0f < 0.999f))
{
return true;
}
}
return false;
}```
this is how I am trying to check state but its returning False when I expect True
How would you suggest checking animator state?
is this placed in like Update or something ?
The easiest way is to put in an Animation Event on the last frame that calls some function. Whenever that function reaches the end, it'll call a function where you can either do something or set a boolean
The downside being that it has to finish. Transitioning away wouldn't call that animation.
OnExitState couldhelp if you got transitions
When I know the Animation Event wont be skipped I usually use that
just be careful with adding AnimationEvent at the end if you have long transition, as this can make it skip
I was just about to say/ask - its important that the Animation Event not get skipped and in the past almost always some kind of bug occurs where its being skipped to the point that I don't trust using them for critical game logic (or any game logic really)
I do have transitions for this one particular animation so Ill google into looking for OnExitState 🤔
If you want to make sure something runs no matter how this animation ends, that's the way to go
Will it proc on just any animation end, or I suppose If I google how OnExitState works Ill get my answer
https://docs.unity3d.com/ScriptReference/StateMachineBehaviour.OnStateExit.html
It gives you a reference to the state being exited, so you can check to make sure it's what you want
Is it possible to have a script as a property in a ScriptableObject without things like Odin? I wanna be able to plugin in a "check if active" script to my powerups that all base on the same interface
That use case sounds like you want to reference an instance, not a script. Which is something you'd need to pass in at runtime, since the instance doesn't exist yet to be assigned
A ScriptableObject is an asset that exists on disk, and it can't reference scene objects for the same reason a prefab can't
So, you could have a field of your interface type, you'd just have to set it in-game after that object is spawned or when the scene is loaded
well looks like odin auto-references that by default in my project i did that in before, for this one i dont have odin available, im gonna think of a different solution then 😄
if it's only a single SO instance you can probably just check a singleton ref?
I have 5 powerups, 2 of those have an option to be turned of in a settings menu, i just wanna check on load if those 2 should be loaded or not and wanted to attach a script to their data each that checks for that setting
why is it not working
Sorry for being rude, but will somebody else address the problem I have? I've marked every section in Publish your project as complete, yet it won't let me continue.
object with script has box collider
other has box collider too
Why not store it in a list-like struct if you don't have a script for those powerups yet?
What is "it" that won't let you continue? What is "Publish your project"?
If you store your settings in a SO you can reference that SO in all objects/prefabs that need to toggle features based on them
The Three Commandments of OnCollisionEnter:
- Thou Shalt have a 3D Collider on each object
- Thou Shalt not tick
isTriggeron either - Thou Shalt have a 3D Rigidbody on at least one of them
It's in Unity Essentials pathway.
I cannot change the structure of the powerups other than adding data, I'm doing work in a project of somebody else, that I cannot structurally change
alr ill try thanks
They're referring to the question previously asked in #💻┃unity-talk message
problem was the rigidbody thanks!!!
Thats a good idea, ill try with that
Ah, I was missing context
Well, he hasn't given the context.
You need to assign an Animator Controller
What does it mean? I'm suggesting you to create a struct in your Manager class, which will reference all those powerups
Yeah but storing all powerups somewhere doesnt help me to disable 2 of them dynamically 😄
And I certainly dont want to do a hard-code check on their names, I need to build a condition into their properties
What is the problem in disabling them if you have their references?
Why would you do a hard-code check on their names if you can just assign them in the Inspector, if they aren't spawned via code? Otherwise, add them to a list when spawning.
I have 5 ScriptableObjects that hold powerup data, they get loaded into a list on startup + the list gets reloaded on settings-save. I want to have a dynamic option on each powerup to disable them when certain conditions are met (in this case option to disable them is checked) in runtime
Should the option be stored via a Func?
I found a way now though, each powerup has an active bool now and the settings save proecess will change the active on the two i need disabled to false
The option should be a function if possible, yes, in my previous project (with odin available) i just added a check script that got auto-referenced by odin, without it seems to not be available so easily
But i found a solution now, so doesnt matter anymore 😄
Alright, if you need a dynamic option, you should have a Func<bool> for those powerups.
If you don't want to change their data, I would consider having, as I have previously mentioned, a struct, which has the Powerup and Func<bool> fields.
The dynamic options cannot be serialized and should be set via code in the e.g. Awake or Start method.
I cant set a func in the scriptable object though, thats the point^^
Alright, you have found a solution now anyway. That's great 
Hello guys i want to make an AR app and link it with a flutter app can someone please tell the steps on how to do that or what do i need for it ?
thats very vague, link it what way?
For exemple you enter the app made with flutter (user interface) then click on play and you are in a the AR
Made using unity
So you're wanting to make a flutter app that can launch a Unity app?
you can probably make it a webgl and embed that or you can use unity as external library
Yess exactly
So i build it on webgl ?
just saying, its an option
there are many ways to do something :p
Consider asking the Flutter social media (forum, discord, etc) else Google. Probably something related to this https://medium.com/@joachimmpanda97/how-to-launch-direct-another-app-from-your-flutter-app-d1daa4687fe6
It's not really related to unity, relative to constraint.
huh what is that? and what is the code part
GameObject effectInstance = Instantiate(effectPrefab, this.transform.position, Quaternion.identity); this works ok but i need to move it up alittle as soon as i do GameObject effectInstance = Instantiate(effectPrefab, this.transform.up * 1.5f, Quaternion.identity); it moves it up but seems to instanciate at the wrong location
Where as the first one does it in correct place
transform.up is a direction not a position
So do i need a local var Vector 3? or would this be the same as transform up
do you not understand what I wrote?
Well, the first one is spawning at this object's position. The second one is spawning at 0, 1.5, 0
it is a direction like I said
here and there are positions, left and right are directions
so to achive it to move up on the y axis by 1.5 it would need to be a vector postion
understand
Then you would be adding 1.5 to the y value of a position
so to go up on the transform Y axis you want
position + (up * 1,5)
ok and not var newPos = new Vector3(transform.position.x, 1.5f, transform.position.z);
that goes to 1.5 not up by 1,5
Think about it like this. If someone said "look up" in real life, would you think they are talking about a specific position, or a direction?
well i can hear a plane in the sky ill look up? would that be a direction haha. yh thanks i understand now
That would set the y value to 1.5
Think of it in 2 dimensions. Where is this point at on the graph? Where is the point 1 space above it?
public class CameraController : MonoBehaviour
{
Transform orientation;
Transform pOrientation;
Transform camera;
[Header("Variables")]
public float camSpeedX = 5.0f;
public float camSpeedY = 3.0f;
void Start()
{
orientation = gameObject.transform.GetChild(1).transform;
camera = gameObject.transform.GetChild(0).transform;
pOrientation = gameObject.transform;
}
void Update()
{
float camX = Input.GetAxis("Mouse X") * camSpeedX;
float camY = -Input.GetAxis("Mouse Y") * camSpeedY;
Quaternion rotation = Quaternion.Euler(camY, camX, 0);
camera.rotation *= rotation;
}
}
so i have this code for my camera but how do i stop my Z axis from changing? it leads to the camera tilting at odd angles after a few movements
Testing an Android APK build and getting the error "App Not Installed" while trying to open the APK.
- Admin permissions granted on the OS
- Last build worked fine.
- No debug information... Unity says it "succeeded" while the app cannot be opened
Any ideas?
Thanks digiholic
thanks steveSmith
Actually I think it's obivious what's happened. One of the versions courrpted the saved data of the app
So now when I reinstall, it wont allow it due to the left over corruption
hello, i want to make it so that whenever the zombie has velocity > 0, it will start an animation
how could i do something like
are you sure you want to do that?
if(rb.velocity > vector3.zero)
!learn . Check out the animation lessons. It's pretty simple
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
idk the other approches
When the velocity is greater than 0, set a parameter in the animator. Use that parameter to determine when to transition to a new animation state
how do i check the velocity when its greater than 0?
if
no like
well, what you ask will start an animation every frame that velocity > 0 and I doubt very much you want that
Just so you know, it is bad practice and not a good idea to directly reference physics like that.
like i showed here
idk what code i could write. ik i have to use if
No, checking velocity is fine
setting it directly is unrealistic but also fine if realism isn't your goal
#💻┃code-beginner message
Use this.
Also consider what steve said
oh sorry, didnt notice it
if statements take in a condition and execute the code inside of them if the condition is true.
So, what is the condition you want to check for?
do i need to clamp the z axis to zero or something?
Can you expand some more on this?
There's no problem with reading the velocity. It doesn't change anything.
You're just checking how fast the object is currently moving
Can you expand on this more? It runs counter to what my experience is, as well as the common wisdom
I would go so far as saying it is just straight up incorrect
i am revamping my enemy in my game. new ai and stuff u can check #1232638796311560224
Maybe that property was not the one I was talking about, but generally the physics engine is unreliable. And directly referencing it with an if statement and threshold with a bool such as playing an animation, you will get unreliable results. I could be wrong, but I'd like to hear your take on it
Physics engine is unreliable?
Unreliable results?
I have not experienced that
It is the case that setting the velocity directly (instead of using AddForce) can lead to non-realistic movement, but oftentimes for a game you want unrealistic movement because having a realistic ramp-up and momentum can make a game feel swimmy and slow
I could be wrong, I'm not trying to prove anything
You shouldn't check if it's exactly a value
but checking that it's non-zero is completely fine. I would probably set a bit of a higher threshold though
Hence why I asked and posted in the #💻┃code-beginner in the last five minutes
Very true. I think realistic and reliable are kinda separate concepts in this case though
I didn't think you were? Just giving my experience.
you are correct, the physics engine if not exact (rather than unreliable). However testing variables for threshold values is perfectly fine
Yea I am purely talking from my own experiences. I tried that MrcJoc asked for when I was first starting, not good results. Then I was told by various people the engine was not reliable unless you stuck to certain settings, and that basing animations of a velcoity threshold is not ideal or "good practice"
^ this I agree with
That is not the issue. It is fine to base it off physics engine. You just have to do it right
As steve said, it is not going to be exact (as opposed to reliable). If you understand that, it will be reliable
Basing animation on velicity is perfectly fine practice, AND common
Honestly this. I should have said the engine gave unreliable results, so basing something such as animation states off it is not a wise idea (or anything that has a definitive state). That's how I should have put it.
you are still using the word unreliable which is incorrect in this context
the values are reliable just not exact
I guess it is more reliable than I thought. Sitting here trying to think of a certain context where you would do what we are talking about though...
Out of interest do you have any working, real examples you could share?
I have been using velocity for setting animations for like 5 years or more. It is perfectly valid
Most of my non-rts motion is dynamic rigidbodies with usually addforce. I really like the impricision
You guys are right, it is reliable, I'm sure it is. I was unaware how reliable it was
Do you have a link to your projects? Even without the code, just want to see it working
Checking if an object's velocity is exactly 3: Bad. Imprecise. You will almost never get that exact number.
Checking if an object's velocity is at least 3: Fine. There's a lot of numbers bigger than 3 that would all satisfy the condition.
No not really. Never published anything. Just a hobby for me.
sure
https://www.youtube.com/@stevesmith.software
Check out any one of the engine videos, all made using Unity physics
Ah yep. Seeing this helped. Doppler effect comes to mind straight away
Personally for animations I went down the road of attempting to base it off the physics engine, didn't have great experience and those around me told me not to do it. So these days I go for a finite state machine and base the state changes on inputs
I actually have a great Domino effect made using Unity Physics, I'll see if I can post a video of it over the weekend
By the way, just reposting so people can see it.
Android APK is corrupted... Phone wont open it with the error "App Not Installed". If anyone knows where Unity saves App Data lmk pls
Ok, so I thought this too, but
- Currently I am not writing any files to that path, it's been disabled for testing.
- I don't use Android much, looking everywhere and I don't know how to access that path. I think it gets deleted when I uninstall the app?
To my understanding I cleared the associated data by uninstalling the app. I also looked over the build details and those are correct
thanks for ALL the help guys..... i figured it out myself lmfao
the path is created whether you use it or not. If it is deleted upon uninstall varies between Android versions. I have seen both behaviours
Ah... the worst news to hear.
Cool. No need to anounce it. The sarcastm is not appreciated
Any way to have a custom asset type? Like how an fbx file is "t:Model" and how sprites are "t:Sprite".
I want my scriptable object to have a type of "t:STrack"
cool... no need to respond lmao
lol
It gets worse. Each major hardware manufacturer has their own version of Android so the behaviour can vary on the same version but from different vendors
t: searches by type (class) name, so you should be able to just put the ScriptableObject's class name to get the correct results
Oh... thank you!
I Fixed the problem... I had to disable some automated thing by Moto, then change another setting, theeeen I could delete it. Such a joke, basically it was just random troubleshooting since as you say, researching it and there's so much different hardware, some with no corresponding docs 🙃
Lol, Android docs, those that exist at all, are virtually useless and certainly not to be relied upon
I'm assuming there is a developer mode that cuts that crap that I'm not aware of yet? I hope so...
why i cant create?
Basically you can go through Android Studio and that's about as good as it gets
I'm so glad Unity exists for app development. Imagine dealing with all that stuff manually... I admittedly have no clue where to start
Seems like you created an Animator Override instead of a regular Animator
Unfortunately I had to learn the hard way. In fact developing and trouble shooting Android apps has become such a major PITA I am dropping the platform completely
Did you do it for games dev or something else?
game and app dev
Did you use or do you know any libraries to make it easier?
no, what we used is all in house stuff
Oh wow. I need to do it eventually so just trying to find the easiest way I can too
Good thing F-droid exists, you can see so many examples
Sorry, no easy way just years of pain
Alright well thx Steve and others for this and the physics question
Wait sorry, I do have one last question. Did you go the software or web-based approach?
Both
I did web app development but it was more front end. I don't really know how the backend works but I'm assuming it's different
For Android/Web we used the Cordova framework, not sure if it still exists but we had very good experiences with it
MAUI is very good for android/ios if you like C# .net ecosystem
what does that mean
Going to sound crazy but how much knowledge is transferable from C# and C++ in games development to that?
I can't be any clearer than that. When you right-clicked the Assets tab to create your Animator, you chose "Animator Override Controller" instead of "Aniamtor Controller"
The file has the .overrideController extension, which is not correct
See the icons in the content browser? They are different to the other animations because you accidentally picked the wrong type
depends on what, most knowledge is transferrable to many languages.
Backend app development
just use c# ?
An Animator Override swaps out the animation clips of an existing Animator Controller without changing any of the logic or transitions.
Yea but that's .Net? Must be pretty different?
So is it different but easy to pick up
.NET is the whole framework ecosystem, including C++
c# is part of the languages supported in .net
Almost nothing, apart from basic language/programming skills is transferable from gamedev to back end dev. They are two very different beasts each with their own specific requirements
Wait what. Can you explain what you mean? Sorry I have looked this up before and didn't get it, you explain it better
there are different variations / app frameworks within .NET
.NET is the ecosystem?
yeah pretty much
So C# and C++ are like components of .NET?
Unity C# IS .NET, it is just covered with easy functions like a API
no they are languages
nothign to do with .net
.NET uses many languages, C# is one of them
C# exists without .net
Ok what these guys said lol. The .NET part doesnt matter much, C# is C#
lol, can't do much with it though
yeah pretty much lol sitting this in mono like waaa
or F# 😈
or even Visual Basic (God rest it's soul)
also visual basic is pretty well supported
What sort of skills are new then? So starting from a game dev background is like starting brand new?
I imagine stuff like databases.
well yeah you have to learn new APIs
For backend linux, Node js is cool too. Unity C# <-> Nodejs has great communication. I know C# but I dont know Node, so asking ChatGPT to write it has been a breeze lol
most of the other logic is tranferring (maaking loops, lists etc)
That's fine, same as switching a game engine
yeah pretty much.
Biggest one of all is an attitude change. If it can possibly go wrong, it will go wrong at some point, so deal with it correctly
also Debugger will be your best friend
Ah, so more error handling and stuff
absolutely
Unity is easier than most others, especially with its C#. You are looking at this backwards. If you are moving from Unity to another engine thats when theres more to learn
.NET already has a great backend to replace node
When Unity finally goes to .Net 7 the whole landscape will change
Eh I enjoyed seeing the node script run. easy command to launch and its just a couple lines of code in a single js script
It may be surprising from all my questions but I made a C++ SDL engine and did some Unreal, yea I agree Unity is way easier. Doesn't mean I am great at C++ btw, just can do it. So I am wondering how easy it would be to transfer to App dev
ew javascript
Node js, not javvascript
TypeScript 
slightly better but still fugly
wtf does it matter, you use the language that gets the job done, end of story.
I could go and ask this on Reddit or something to general programmers but it's easier to get answers from Games programmers who have done both because they are talking from definite experience
I didnt write it. I asked chatgpt and it gave me a unity script to read/write to the server node js script it gave me 100%, which does integrity checks and links to a database.
oh gpt.. I bet it put the database connection string in the client code
No, it encrypted the unity script to hide the domain, and it verifies the scores on the server node program before the node program uploads it to SQL
without asking it added sql injection prot
sry, not script exactly, but the domain/ip
it gave me some key generator
Try it yourself lol - ask gpt
I dont need to , I do it properly with REST/ API calls
storing anything on client is hackable
nothing is stored on the client, and its a singleplayer game
just saying, storing any connection string/ip in client to connect is unwise
Hey guys! Very beginner question here: Would setting the active state of a game object in Unity to its current state have any impact or performance implications? Or does Unity optimize for such cases, preventing redundant operations?
Wondering if I should always make a check before setting the state (if game object not already active, set it active)
the gameobject is already loaded into memory
show me a script that connects to a dedicated server/node without needing a ip or domain
id love to use that instead
No smart person would put a dirrect connect in the client
You make API calls
to the server
authenticate using cookies / tokens
its a offline game to store settings
then a database is overkill
doesnt matter much if it has a domain in the code, which is encrypted tho
the code to verify stuff is server side
the same thing that encrypts it, unless its on the server can be reversed engineered
the only database code visible is on the server app
the game does not connect to a databse
right so you have to write server code in javascript now
the game sends a web request to the server/node, and the server checks the data, if its fine then it uploads to database. I didnt write the code, gpt did
which is why I doubt its method
well it works
idk to me thats more of a hassle than using what .NET already has built in. Asp.net app all the way 🤷♂️ no dealing with JS/TS
I made a players dashboard/admin panel for my game using WebAPI and server
writing a .NET app for a server is the same as running a Node script thats a couple lines, maybe 15. theres no hassle, the code was given by gpt lol
Writing it in .NET does not take away the fact you still have to write code
all I can say is, you seemed to have not gotten deep the rabbit hole yet to know what you're talking about here
i prefer writing the backend in c#, now you can copy and paste (or use the dll) of your api classes and the logic of verification
sharing Class Libraries isa breeze, not having to write code over and over again
You are trying to say that .NET is less work, but its no actual difference, its the same amount of code.
Amount of code is really not an important factor at all
Unless it is extremes
where did I say its less work?
I said if you're doing c# it only makes sense to continue using C# than dealing with another language.
Also its foolish thinking what GPT gave you is scalable
before doubting, ask it, you might be surprised.
Its not even doubt, I've experienced it
GPT doesnt write scalable code..
it has no reason or forethought
We have all tried gpt. You act as if we haven't.
Ignoring the immorality of it, it's just been a constant let down in my experience.
Including gpt 4
then you didnt provide enough info on what you need
How so ? I knew exactly what I want to build
Ive learned a good bit from it, I dont copy paste code from it
its not an instruction issue, its a Listener/Student issue
so if something breaks you know how to fix it?
try again once you know how to code
No, ChatGPT cannot make scaleable code because it is literally incapable of forethought. It can't plan for the future because it doesn't even have a present. It's not magic and it's not alive, it's a very complicated markov chain
so you're saying GPT not understanding is me not knowing how to code?
I promise that navarone knows how to code quite well
that makes no sense
Hahahaha
Oh wow
already scaled up 4 games to AWS/Azure.. I dont think its my lack of "code knowledge"
Gotta love these people that seem to think that these LLM's even know how to code. Guess what? They do not!
Its a fair learning tool, im ofc not going to copy all of its code, the thing is I dont know Nodejs code so it was fine to learn from it.