#💻┃code-beginner
1 messages · Page 327 of 1
i thought u have already moved it once tho?
isn't rotating an object counted as movement related to physics?
Maybe, just maybe resize the collider instead of moving the mesh.
not really
unless you had a physics body
Update() should be fine for camera rotation
ok. anyways, if i want the camera to be framerate-independent, then should i use FixedUpdate() or Time.DeltaTime ?
When someone says physics, we assume it means handled by Physx or Box2D
ok, thanks.
Should do it in LateUpdate generally
But Update is fine too
And yeah, for setting position, use deltaTime
if ur animation is locking it on the Y so u can't move it downwards create a Container for it and move that down instead
just dont use deltaTime on mouse input
ok
also the two are not related (FixedUpdate . Time.deltaTime)
i will try doing both Update and LateUpdate, i'll see what works better for me
is there a way to only pause one scene
should i just restart the whole thing?
wdym one scene ?
there is no pause function
yeah with time.timescale
that only works for limited objects
that is okay
thats gonna change the timescale for everything..
i think its a global setting , doubt u can do it per scene
you would have to do it individually, custom Constant
so pause singular objects
ya, could use a boolean in each script u want to pause.. for example
is there specific reason you need to only pause one scene
if(!paused){
//do all the logic u were already doing
}```
A manager with an enum, everything subscribes to it, the enum can be PauseSceneX, PauseAllScenes, UnPause.
Depending on enum, the code does an early return
this sounds like something google would already have an answer for
if its possible that is
im having it load a new scene upon hit and then when that new scene is completed it goes back to the original
so i need the stuff in the scene i load out of to stay in place
am i wrong to think that unity probably should have added some scene.pause function or something
You just need to save the position and velocity of all the objects, and the state of all your scripts, and then reload that.
okay
Or, don't load in a new scene, just do it on another layer of your existing scene.
thank you
i think layer is a good idea for me cause i am not that good at coding to know how to do the other one
Making a pacing enemy detect bottomless pits
can someone help me about a raycast problem?
I dont know why, my enemy dont generate raycasts
sorry, I mean if this was the place for it xD
It is. Just ask
I have that code
well, is part of the code
basically is a state machine for a fps enemy
when the enemy is searching, the idea is that it generates a raycast
so did you check the Debug.DrawRay
array ?
did you enable Gizmos in the Gameview
either script is not running or your ray doesn't have correct values
this option right?
well yeah if you are observing it in scene view during playmode
otherwise in gameview it has its own toggle
move it outside of the If statement of ray
I think everything is alright
defeats the whole point of debugging drawing a ray only if hits
put it above the if statement
maybe the origin being wrong
0.5f
I think you want
Vector3 pos =myEnemy.transform.position;
pos.y += 0.5f;
var ray = new Ray(pos, myEnemy.transform.forward)```
where is it
ok. your gameObject origin point is prob not where you think it is
youre right
also can barely tell whats going on in that image
might need ray.position = transform.position
make sure you have this setup like so
I had it on center instead of pivot
but the problem remains
is extremely strange
nothing strange about it
switching it from Local to Center is not the fix
its simply to view the true Pivot poiint
you have to show what myEnemy is
that way when you use transform.position you know what position that is
i think [Pivot] [Local] should be the default setting
yup been preaching it for years
lol
my enemy is that small cube
unity wont listen.
it confuses things for those who don't know those will create alignment problems later
myEnemy* sorry
the strange thibg is that, depending on how I move the camera
the ray cast move
i meant the inspector though
that cube is linked in the inspector for the field myEnemy ?
cause the forward doesn't match up if thats the ray being drawn
this?
myEnemy.transform.forward * 100f this should be drawing the debug ray directly on top of the blue axis
wdym calling this script
we need that to be an emoji
make sure object full inspector is visible with hierarchy
ok
fr
jesus man
its like no cap but no crop
!nocrop
from your point of view guys is probably like talking to a gorilla xD
lol, nah we're just being thorough
Sorry if I'm interrupting something, hopefully this is an easy answer. I'm trying to get a bullet to pass through the player as if they don't exist. However the bullet still slows down when passing through the player. Why would this be and how can I fix it?
because its colliding before you apply Ignore
thats what I expected, but Im not sure how to fix it lol
physics step happens before OnCollisionXXX runs. why not just make the bullet a trigger instead?
maybe layerbased on do it in the beginning
from a cenital point of view it seems that the raycast is originating from the cube
but it stills not collides with the player
the origin is fine
the direction is wrong though
transform.forward should be on blue
oh
you tried this btw
#💻┃code-beginner message
hah welcome to gamedev
I'm sorry (again), but in that code that you pass me should I just change the variables or copy paste?
should be fine to copy and paste it
for both DrawRay n Raycast
again, a troglodyte question but honestly I'm therrible at programing
well its easier to start with the basics instead of already doing raycasts and state machines lol
yea...
does anyone have any idea on why this happens
I'm honestly trying to adapt but is difficult
because you have Jump nested inside of another method
read the green underline under Jump
i see..
man, I dont know where to paste it xD
wdym
oh ur right
thanks everythings good now 🙂
DrawRay(ray.origin, ray.direction * length, . . )
like this¿
oh sorry I change it to blue before
then it should not be nested inside Physics If statement
put above it like i said earlier
Debug.DrawRay(ray.origin, ray.direction , Color.blue); like this?
there it is!
(change it to red again, seems clearer)
but I dont undertand
why it still dont detect the player?
I put the FPSController right in front of the ray and still nothing
the tag is correct
start debugging
you. already looked visually
now debug the hit
Debug.Log the raycast hit's collider name/tag etc
also did you put 100? cause that doesnt look like *100
well, I already have this
why are u not using the ray u just made for the raycast..
that debugs if the raycast hits a collider
you're still using the old incorrect one?
it's debugger, black is a List<ChessVector/*(my custom class)*/>, why it can not work?
how can I add first person animations? like when im standing still I want a idle animation to play,when walking I want a walking animation to play. all the videos I find are hard to understand cause they don't explain things properly and they edit the video and everything is too fast.
if you want something bigger use a cast like sphere
Are you referring to the Ray's length? There is a parameter for this
btw .CompareTag("Player") is better than ==
oh, thx for the tip
yea
oh right make it longer if you mean length
forgot default is like 1 length
have you set up equality checks on your class? if not, then by default it compares the reference not the contents of the class
Your Ray has a parameter for the length. Usually the last one.
There are quite a few overloads
you can use length: and order wont matter
but other params will need i think
too bad
Probably hould use a struct for this not a class. And yeah you need to implement IEquatable and HashCode/Equals for this
There are not a lot
yes
but did you implement .Equals and HashCode?
List doesn't use == to compare things
no
You need to implement Equals and HashCode
ok, what code row i need for implement it?
code row?
I think this that this should do
What's a code row?
thanks a lot guys
wait wat was it?
like this public static bool operator ==(ChessVector v1, ChessVector v2) for == operator
object notNull1 = null ?? v1
what?
Yes, that's right. So the length was the Raycast's parameter.
make sure thats the correct field
seems good in game
just built me a raycast fidget toy 😄
I think because they were creating the ray origin as world pos y
Im going to also apply it to the drawray
no draw ray doesnt have a length
thats why you multiply direction by length
Also again definitely consider using a struct not a class
and use Vector2Int for inspiration:
https://github.com/Unity-Technologies/UnityCsReference/blob/9778aaee88c7de7656c15184ba5c91ca66db7e94/Runtime/Export/Math/Vector2Int.cs#L222
https://github.com/Unity-Technologies/UnityCsReference/blob/9778aaee88c7de7656c15184ba5c91ca66db7e94/Runtime/Export/Math/Vector2Int.cs#L236
oh ok
private void OnDrawGizmos()
{
if(draw)
{
if(success) Gizmos.color = rayHitColor;
else Gizmos.color = rayColor;
Gizmos.DrawRay(transform.position,targetDir * rayDistance);
}
}```
i like to use OnDrawGizmo's function
or ...GizmosSelected()
then u can just use the same ray just as it is
(if u construct a ray for ur raycast, that is)
Gizmos.color = success? rayHitColor : rayColor
Where is the ternary operator?
lol i knew it!
is ok thought, the lenght multiplier works fine in game
im workin on it 😅
dat sweet sweet one line goodness
thx
it'll make up for my chunky switch
This can be simplified
that can also be simplified btw
how?
targetDir = direction switch
{
Direction.North => ...,
};
ohhh
i think you can let VS refactor it for you
i let it build the switch.. thought it was good enuff haha
ctrl + .
i didn't even think of htis
less lines = better code. amirite?
/s
also, want to ask, are there easy solutions in code to hide a mechanic until the player touch a special gameobject? Im making a small metroidvania and I know there are better solutions than having to set on and off 3 different character with 1, 2 or 3 mechanics
But this is cool to do 
keep the script disabled until player touches the thing
lol, thats brilliant
keep it simple
thx man
apply that to everything from now
if u dont see it, turn it off 😄
performance gains!
I used to have bools spammed everywhere
my inventory basically was a bunch of bools 😆
good times
my original plan was to just set off the character that unlock the ability and set on another character with that ability
but that is barbaric xD
depends, if the character has to change much it might make sense to only switch visuals
(barbaric for a programmer, I butcher the sacred code of C# with my letters mind)
I think yours is better, the game is more like a prototipe
it will have like 2 o 3 power ups
black mesa 2 ?
GenerateElevationGrid(mesh, Resolution, new Vector3(-0.5f, 0.0f, -0.5f));
Black Mesa 2?
yea just silly joke
I see. It is not that. It's google earth as a mod for a flight simulation
But it only works at half the resolution it could
Ohh cool so you're trying to modify the terrain
I generated the terrain at runtime. I'm just trying to make the mesh a higher resolution
How can i convert a ModelImporterClipAnimation to an animation clip?
is there anything about this script to handle my game's AI i could improve? - i want a nice, neat, hopefully flexible script.
!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.
Yes my bad sorry, didnt mean to send yet
if it works it works. If you want flexible script dont cram everything into one script
haha cheers, thats been a recurring theme, ive not crammed too much unrelated stuff into it though just some sfx and ui stuff
also tbh
}
else
lookTarget = baseLookAt;
imo without {} it doesn't look as good
not a fan of doing that esp if its nested inside other if statements
👍
btw if you want cleaner conditions
this is better pattern to use imo
https://www.c-sharpcorner.com/article/early-return-pattern-in-c-sharp/
It's really a game changer when you get used to early returns
sorry
My first code ^_^
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Windows;
public class PlayerScript : MonoBehaviour
{
public float Speed = 0.006f;
public float HSpeed = 0.009f;
void Start()
{
}
void Update()
{
// Player Movement
if (UnityEngine.Input.GetKey(KeyCode.A) || UnityEngine.Input.GetKey(KeyCode.LeftArrow))
{
transform.Translate(new Vector3(-Speed, 0, 0));
}
else if (UnityEngine.Input.GetKey(KeyCode.D) || UnityEngine.Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(new Vector3(Speed, 0, 0));
}
if (UnityEngine.Input.GetKey(KeyCode.A) && (UnityEngine.Input.GetKey(KeyCode.LeftShift) || UnityEngine.Input.GetKey(KeyCode.LeftArrow) && (UnityEngine.Input.GetKey(KeyCode.LeftShift))))
{
transform.Translate(new Vector3(-HSpeed, 0, 0));
}
else if (UnityEngine.Input.GetKey(KeyCode.D) && (UnityEngine.Input.GetKey(KeyCode.LeftShift) || UnityEngine.Input.GetKey(KeyCode.RightArrow) && (UnityEngine.Input.GetKey(KeyCode.LeftShift))))
{
transform.Translate(new Vector3(HSpeed, 0, 0));
}
}
}```
any suggestion ?
nice, however you should use a Rigidbody/CharacterController to move, and for easier input you can use Input.GetAxis("Horizontal") same with Vertical, or use the new Input System
can easily bring this code down to 3-5 lines which would make it a lot cleaner and nicer to read
Thanks ^_^
i'm making 2d game
then you can use a Rigidbody2D
and set its .velocity or use AddForce()
yes
oh you already have one?
you arent moving via it though
https://hastebin.com/share/ilepizawuc.csharp how come when the katana hits an enemy it comes back fine but if it doesnt hit an enemy it just flies off into the distance
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
do you actually make it come back if it doesnt hit an enemy? what line is that code on
yes it says startcoroutine and starts the followhand coroutine once you throw it after a certain amount of time
Why are you using Invoke with a coroutine?
because i am trying to start it after a cooldwon
The way to start a coroutine is to use StartCoroutine()
Hello is it possible to put multiple collider in a procedural mesh ?
ik but it doesnt when i do it like that
the point of a couroutine is you can add a wait inside it
What doesn't what when you do it like that?
i want it to start the cooldwon after you throw it but if i do it like that it starts after you hit an enemy meaning it works fine if you dont hiot an enemy but if you do then it continues to go for the cooldwon
RIght now your FollowHand will never run
because you cannot start a coroutine with Invoke
just start the coroutine
and put yield return new WaitForSeconds(time); as the first line
then you can use a bool, if you hit an enemy then make it true and dont run the cooldown if its true
No it won't
exactly what i did
IEnumerator FollowHand()
{
yield return new WaitForSeconds(timeForKatanaToReturnAfterThrown);
while (Vector3.Distance(transform.position, hand.position) > .2f)
{
returningSword = true;
rb.velocity = (hand.position - transform.position) * returnForce;
returnForce += Time.deltaTime * 5;
transform.Rotate(returnSpinSpeed, 0, 0);
yield return null;
}
CatchSword();
}
ok but where did you call StartCoroutine
then it will be fine
its not tho
Add Debug.Logs to your code
Honestly you've made this quite overcomplex
and there's a lot of moving pieces
From the looks of things there's about a half dozen functions that are never used
Start adding log statements so you can figure out what's actually happening
ye cuz i was using them before
i debugged returning sword and it starts after the cooldown after the enemy was hit
use a bool or a paramater
i am
show it then
around the cooldown, or you can do a paramater when you start the coroutine to know if its from the OnTriggerEnter or not
What is "returning sword"?
show the code
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
You need to put a log inside FollowHand
put a log right before the WaitForSeconds
and right after
like "Starting cooldown before following hand". and "Cooldown over, starting to follow hand now"
ok
i think it starts the cooldown twice, once when you throw the katana and once when the enemy is hit
Okay, so, you throw the sword by giving it a force and starting up two timers. One spins the sword until it starts to return. The other waits some period of time before it returns.
Additionally, whenever this object collides with an enemy, you cancel any existing spins and returns, then start up another wait and return
show the logs
I mean duh - look at what your code does in OnTriggerEnter:
StopAllCoroutines();
StartCoroutine(FollowHand());```
it's doing exactly what you tell it to do
so it sounds like you need separate functionality for when thrown vs when colliding
when it collides you want to start returning right away
when it's thrown, you want to start a cooldown, after which it returns right away
you can just add a parameter for how long to wait to the coroutine if you wish
that would be one simple way to do it
so i just change the cooldown to 0 if it collides
you don't "change" the cooldown, you just pass in 0 as the parameter
and pass in the normal cooldown in the other case
ok
it worked ty
there really isn't a good place to ask this... but someone pushed changes to a scene that they shouldn't have and now unity is saying the file is confliceted when the good copy was recovered from stash. How is it even possible the stash file was changed? how do I get my copy of the scene back
(involving git)
What strategies are advised for managing game object hierarchy during runtime? I've not really concerned myself it thus far, but after a while of using Instantiate()... the Scene Heirarchy is unusable with thousands of objects listed. I've been pondering if its at all useful or feasible to try and collect them under other objects, if only to make the Editor faster and for my own sanity. Do folks generally do that at some point? Or am I missing a design principle here that I should be using?
The stashed file hasn't changed, the conflict comes from the scene in your local branch compared to the stashed one
then why won't unity load it and says its conflicted.
unity says that
not git
Ah, yeah they might have the same unique identifier
=> #💻┃unity-talk as it's not a code issue
when you instantiate there is a paramater for setting the parent
also what are you instantiating?
if its bullets or something you can use pooling
Nah, not bullets. Say I have 32 doors on the map, 10 altars, 50 beds, a couple cabinets, and 150 NPCs.
I've not really paid much attention to where the objects end up. They are all tracked/managed by other objects. I could stash them under those manager objects. Just hadn't really thought about if its useful beyond keeping the Editor organized.
your instantiating all of this?
Yes, for example when loading the map from a JSON file to build it up
My current architecture is a reusable scene where the specifics of the map are all loaded dynamically from JSON files created with an editor I wrote.
ah ok, yeah i guess i would just make a parent like Beds Doors NPCS and place them under that
Cool. That is what I figured. Just wanted to bounce it off someone 🙂 Thanks!
Maybe this might help: https://blog.unity.com/engine-platform/best-practices-from-the-spotlight-team-optimizing-the-hierarchy
In short, Unity will mark a GameObject as "dirty" if it, or any of its children have changes, such as position/scale/rotation changes, toggling the object on/off, so if you have a parent with 300 children, and you enable 1 of those chidren, 300 children + the parent get recalculated, even tho almost nothing changed
That said, for your own sanity, organizing objects under a parent can be helpful, or what some do is use a empty object and structure their hierarchy like
==== ENEMEIES ==== (Empty GameObject)
Enemy A (Prefab)
Enemy B (Prefab)
...
==== LIGHTS ==== (Empty GameObject)
...
Personally not a fan of that approach, but for compiling, if your objects ever change, and they dont really need to be a child of anything, its usually best to leave it in the root hierarchy with no parent, otherwise just keep the "dirty" in mind, and if its only for your own sanity, then organize it however is best for you to work, as it likely wont be the major bottleneck of performance, unless the child tree is VERY large
Oh huh, that is very interesting.
I wonder if anyone has made an Asset that allows organization of objects in a secondary tree/heirachy for easier debugging/editing, while still allowing for a performant existence. Given my target includes mobile, I would not want to incur the CPU hit of aggressively grouping objects it seems.
there's no real reason to group an object under a parent, unless it's applicable to its function . . .
can someone walk me through how I can add an online leaderboard system (I ve watched some videos but still cant figure it out but I think im close to the answer)
Yeah my thoughts were entirely geared towards easier navigating of the editor during debugging, and better performance when the list has 1000s of things in it being updated every frame.
what do you mean
Be considerate of parenting. It is mostly for making sure the position of the child is relative to the parent
when playing the game, no one sees the hierarchy. it's unnecessary to group objects that don't actually need grouping. e.g., bullets placed under a projectile GameObject, or enemies as children of an enemies GameObject
it's nice and easy to sift through while editing, but during gameplay, it not helpful. you can still use parenting if you move the objects locally. the biggest culprit is updating transform.position without knowing the consequences . . .
are u saying before building a project that objects which are parented for organisation should be unparented
Hey guys, I'm trying to use animator events to play sounds in my game. But it doesn't seem to work? I tried to have it when the method is executed it should tell me a Debug.Log("FootStep!!"); but it doesn't show.
No
Just don't parent them in the first place if you don't have to
You'd have to show what you tried
no, if you need that parent-child relationship, then keep it; but don't unnecessarily parent objects for that sake of organization . . .
why not
If you click and read the article that was posted, you'll see that it can kill game performance.
i already explained that above . . .
i will read that
check out the article for more info . . .
https://blog.unity.com/engine-platform/best-practices-from-the-spotlight-team-optimizing-the-hierarchy
Can someone explain to me how I could recreate the shooting that takes place in this video (2:27 - 3:00)? How are the bullets able to go over the enemies in a 2D game but not collide with them? Is it because of the z values of their position? Also how is the player able to control how high or low their bullets go? https://www.youtube.com/watch?v=OBTud6ujDDw
Video from the C64 game "Beach Head"
The video is downloadable at
http://www.archive.org/details/C64Videoarchive200-50longplays_part1
Yes 🦧 😎
this event should call this function. (Second image) that uses an event system I made for my game to not rely on dependencies that much. but the function doesn't event show the debug.log
There's almost zero chance this game is using an actual physics engine
it is doing its own internal accounting of object positions and collision detection
But how could I recreate that in Unity?
Write your own physics
what
it's really not that complicated here. Probably just a bunch of circle or square overlaps
But like I can't I do by setting their z values differently
Why not
Yea but I don't know how to do that
Then this may be too large of a project at the moment.
Do some prototypes of just different physics interactions
Work up to it. You got this
For two sphere's it's literally just checking if the distance is less than the sum of their radiuses
But I mean my game design teacher kinda told me to this
it's any GameObject that is parented to another. using Instantiate just creates a GameObject . . .
what components are attached to the object with the animator?
Then they should have given you resources
Okay but this doesn't explain how I would code it or set it up in Unity?
I just have this video :/
Now you're jsut asking me "what are the basics of coding"
It kinda does
Then they are a bad teacher
Well I can't say that to them
so what is incorrect about me saying to have them organised during development then unparent before building
The animator is in my player object.
The event is calling from the PlayerAudioManager script which holds the (Second image from the message before.)
Why unparent them at that point?
Development work is a big deal
for optimisation like what the site says
Has anyone had any issues with cinemachine not following the player transform when "apply root motion" is checked on?
I recommend watching some tutorial videos to understand the basics of Unity, coding, setting up the project and doing some basic things in 2D. Expect to spend a couple days just watching and learning and then you'll have the foundations for trying to tackle something like this. Code Monkey's earlier videos deal mostly with 2D, explore many facets of game designs and systems, and although some might be more geared towards Unity 2020/21, are still highly applicable to 2022 LTS.
it's unreasonable, especially, if you have tons or hundreds and GameObjects in a scene . . .
why parent in the first place?
organisation
Are you sure that particular animation clip is actually playing?
but if you want to do the extra work, no one is stopping you . . .
Static objects are fine being organized like that
Static things are gonna need the most organization too
For other things, just don't parent them
yes its called within the blend tree i made when the player inputs the y axis of the player.
i understand
Do you think it would be possible to have it done in 3ish days
Just to give some insight, I have about a dozen Manager objects that contain very useful information for Runtime debug. I'm often inspecting them and their properties to track down bugs or just track metrics. If I'm trying to find them amongst 10,000 things in the hierarchy list its a bit of a pain. Not to mention the list itself can lag after some time. There are times I just want to come back after running for 10 hours and inspect a few random objects for integrity and so grouping is helpful in that case. In my case since everything is instantiated at runtime I can just have a flag to tell it to group for debug/test and ungroup when I go live. But its great to have learned of the performance implications so I can plan accordingly.
long ass run
I'm not sure what's wrong. Maybe check #🏃┃animation
Thanks for trying to help, this thing is driving me nuts since yesterday.
maybe something about the blend or transition skips those first animation frames so the event doesn't work?
I don't know what all "have it done" means per say... but a simple game-scene like that? Sure if you are a competent C# coder and have experience with Unity, that's probably a weekend game jam 20 hour project. If you are new to Unity/coding I'd say more like a month.
That is a possibility? But I've tried on putting the event in the middle of the animation, and it still didn't work.
have you tried starting the game and then playing the anim on loop from the animation window just to check
you can easily search the hierarchy based on name, component, etc. if they're manager objects, that should be a cinch . . .
you can watch the line go over the animation and make sure it goes past the event trigger
Yes I have, it still didn't work.
Yes, I did just that. But the debug.log I wrote as an indicator, still doesn't show.
are you calling a function on a component attached to the same GameObject?
would also just make sure that the void is set to activate from that trigger
Yes, I am. Its with my player object. The method is in my PlayerAudioManager
void is set? Like as a data type?
by void they probably mean the function/method . . .
It is a void data type.
void is just a return type, it's not relatable to a method. that's why the confusion . . .
could you explain simpler fo me
Yeah, because int and other data types can be a method. Void just doesn't return value. (Afaik)
Are you sure there's nothing printing in the console? Can you show us the console window after the event should have been triggered?
i am just talking about when you select the animation event and set it to activate the function contained in a void
Okay.
They are not called voids
Function in a void?😱
It is set.
You have messages disabled in the console...
The "it" IS the function
you have 5 messages from the console and 1 error, but only the error is displayed . . .
The stuff inside is the body of the function (method)
i see
Oh yeah, sorry. but no. the messages in the console is sent by my npc ai random movement
There's nothing else than that.
isnt calling it a void just more direct or can that be confused with other things
It is meaningless. Void is a return type. Never call it void
public void
I forgot I have it setted as that.
[Accessor] [return type]
is there anyone that can teach me the basics of c# use in unity?
are there other types that dont return
Yes, I have it set now to show all but it still doesn't work.
no, because they are not voids. if a method has public int, calling it an int makes no sense and is very confusing . . .
ty
Irrelevant. Call it a method
Calling it a void immediately exposes a lack of knowledge/experience, and confuses beginners
Also !learn btw
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Is the first message not related as well? We can't see it.
oh dang thanks @summer stump
waht would you call a public int
Depends on the context. Without anything it's just an accessory and a type.
Yes, its from my ai. I was experimenting with a patrol ai before.
a method, like normal . . .
Ok yeah, see why that is confusing. An int is a type. Public int could be talking about a method with an int return or a variable or a property
Public int isn't called anything, it is part of multiple things
Wait, did you try playing the animation via the animator..?
I want to do like this thing where enemies gradually change color when they get status effects like Freezing (turning blue gradually). Is that supposed to be like a custom shader or I can do simple script that adds a semitransparent layer of a given color on top of the material? Cause I am not sure at all on how to handle something like that
Yeah?? That's what I did in the video?
I'm not sure a preview window would trigger it correctly.
No, you clicked preview button.
Oh. What do you mean via animator? Like from this?
Yes
Also, I'd remove the other debug logs for the time being as they're gonna make it more difficult to see the event message.
Does anyone know how to fix this error? I'm working with WebGL and it won't give me the preview
There must be more errors other than that.
Yes, you are right. But now it works? I don't understand? It was not working before. Lol. Thank you.
It just crashed my Unity so I'm unable to check that but I will see if i can track any more down
your error might be stopping the code from running
Perhaps the issue had more causes than you thought. Some of the changes fixed the previous cause, but then you started testing in the preview mode and couldn't see that.
Read the warning. It's probably related to the issue.
Or not. Share the first error details.
I'm not quite sure what it means. How is it able to be completed as a build but wont open in WebGL? The only reasons it gives me is 'result of Failed' and 'no further information'
Wdym? It doesn't complete the build. It fails to do so.
Yes, it would seem that way. Thanks.
it says 'build completed with a result of failed', does that mean the build did not complete at all? it still saved to my folder on my desktop
Here are details for the first error
Yes, it means that the build failed. Even if there are some files that it produced, it shouldn't be able to run.
where can i read what all the stuff is called
Share the whole error details. Use !code sharing guidelines
📃 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.
In the C# manual
Any basic c# course
This is one I always recommend
https://www.w3schools.com/cs/index.php
does it not vary in unity
Or yeah, the microsoft c# manual is peak
It does not
okay ty
Unity is a c# api. It has methods ON TOP of c#
It doesn't change anything with c# itself
i tried doing the ```cs
// Your code here
but it only let me send as this because it was too much text
you are cooked

I'm using the KinematicCharacterController from the Unity Asset store, and I need to use it for my assignment so the fact its not working is a huge problem 
i have
i also talked to my TA about it and he has no idea either
google just kind of says 'yeah that certainly is an error that exists'
i was shown a good amount of unity forum stuff
thats what we're trying to work off of right now yeah
i just meant there wasnt one end all be all answer unfortunately
Look at the "large code blocks" section...
it showed up as one big line of code when i pasted it into one of the listed websites
So what?
Better than having to download the file
Oh i thought i was doing something wrong and it was supposed to show up as multiple lines my bad 
i was shown a code box wut
so was I haha
Mobile vs desktop
gotcha
A large portion of the resident helpers here are on mobile
I managed to figure it out (for now at least); completely had to restart though. It was an issue with my folder organization I believe
which is why the errors were so odd I assume
real quick, will this work?
define "work"?
what are you trying to do?
BoxCast doesn't do collisions
it just tells you if there are objects in the path of the cast box
damn
yes, that's what I meant
you won't move if something's in the way
I'll show the full script so far
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
private Vector3 lastMoveDir = new Vector3(0, 0, 0);
private float playerSize = 2;
private void Update() {
Vector2 inputVector = new Vector2(0, 0);
if (Input.GetKeyDown(KeyCode.W)) {
inputVector.y -= 1;
}
if (Input.GetKeyDown(KeyCode.S)) {
inputVector.y += 1;
}
if (Input.GetKeyDown(KeyCode.A)) {
inputVector.x += 1;
}
if (Input.GetKeyDown(KeyCode.D)) {
inputVector.x -= 1;
}
inputVector.x *= playerSize;
inputVector.y *= playerSize;
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
bool canMove = !Physics.BoxCast(transform.position + moveDir, new Vector3(playerSize, playerSize, playerSize), moveDir);
if (canMove) {
if (moveDir != Vector3.zero) {
lastMoveDir = moveDir;
}
transform.position += moveDir;
transform.forward = lastMoveDir;
}
}
}
- Your first parameter is wrong, it should just be the current position
- This shouldn't really just be a yes or no
You should be looking for the distance you can move
which the boxcast will tell you in the RaycastHit (when you use a form that gives you one)
I probably don't understand what you mean, but it's locked to 1 space at a time, it's a grid based game
Oh I see
this is wrong though:
transform.position + moveDir
but really]
if you have a grid based game
why are you using physics at all??
to check if something's in the way
You should just have a dictionary or a 2D array storing what's in all the grid coordinates
then all you do is see if something is in the grid coordinate you want to move to
much cleaner, more efficient, more logical
idk
Hello! I'm making a 2D platformer and I'm trying to make this Hammer Brother-like enemy.. It walks back and forth a limited distance, always faces the player to throw projectiles their way, and must move away from bottomless pits. Right now, though, it doesn't do the latter. It only detects them when walking off. https://hatebin.com/vgeqlwqeyd
there will be off grid stuff
Anyway what you have will work but you need to change this:
!Physics.BoxCast(transform.position + moveDir, new Vector3(playerSize, playerSize, playerSize), moveDir);
like fences
to this:
!Physics.BoxCast(transform.position, new Vector3(playerSize, playerSize, playerSize), moveDir);
bool canMove = !Physics.BoxCast(transform.position, new Vector3(playerSize, playerSize, playerSize), moveDir);
like this?
that's definitely still representable in a graph data structure but you're a beginner so you'll end up using physics no matter what I say
yes
also is there a way to shorthand a vector3 with all the same arguments passed?
Vector3.one * playerSize
or just store the size as a Vector3 in the first place
really you should just do a CheckBox in the spot you want to move to
not a BoxCast
will that work the same?
rn it's bumping into air
no wait wait
my bad
divide by 2, forgot that
rn it only checks for pit if you are further than move distance
what's telling you that
Btw you're not using a layer mask or antthing right now
so it will likely consider the player itself an obstacle
the player by not moving
This part:
if (canFlip && ...)
{
if (DetectBottomlessPit())
{
...
}
}```
Should perhaps be like:
```c#
else if (canFlip && ...)
{
//Make it an else, since there's no need to check this if you already flipped because of a wall
}
else if (DetectBottomlessPit())
{
...
}
also since you're using a box exactly the size of these things it's finicky
one of many reasons not to use physics for this
maybe use a slightly smaller box
or just use a CheckSphere that's small in the desired grid space
let's use the checkbox like you told me
use a smaller box for it
well
if I look in the direction of a wall that shares an axis with me, it doesn't move
I noticed
If i have 2 separate assemblies, can there be two classes (one in either of them) with the same name and namespace?
Or is this an error?
I used a smaller one here tho, so the corners work
it was indeed overlap
@brittle isle
You only check for pits if you are far from your starting point, try this ↑
DetectBottomlessPit() is useless right now:
You need to move the boxCenter based on which way you're moving.
Right now, it will always return false unless you're already in a pit, because it detects the floor it's standing on.
Hey y'all, there's a project I've been wanting to do for a while and I think Unity might be the easiest way to do it. I've never really programmed before save for a quick Python course, so I'm not really sure what I'm doing. What should I know before getting started? I want to make a VR application to do some simple things.
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Thank you
for a card battling game when a card uses one of their abilities, should the card have a method and affects the other cards in battle? or pass along fields to a method within the battle runtime which already contains all the effected cards
you start the coroutine before the pool has been set up so the dictionary is null
so how do i deal with that
set up the pool inside of Awake instead of Start and it will not be null at the time you access it
okay lemme do it
is awake before start
yes
oh thank you @slender nymph, its fixed
also why do you assign op using FindObjectOfType then reassign it using the singleton's instance variable if it is not null?
i was earlier trying to fix this same issue, so I tried doing this
i can remove it now
you can also use the instance variable to assign it in Start instead of using FindObjectOfType. it being a singleton is supposed to give easy access to it without using any of the Find methods
yes
how did boxfriend become so good at this 🤔
several years of experience
{
if (!poolDictionary.ContainsKey(tag))
{
Debug.LogWarning(tag + " Doesnt exist");
Debug.Log("TAG:" + tag);
return null;
}
Debug.Log("TAG:" + tag);
GameObject objectToSpawn = poolDictionary[tag].Dequeue();
objectToSpawn.transform.position = position;
objectToSpawn.transform.rotation = Quaternion.identity;
objectToSpawn.SetActive(true);
poolDictionary[tag].Enqueue(objectToSpawn);
return objectToSpawn;
}```
I want to create a method like this which deactivates the gameobject using SetActive(False). But How do I approach it? Do I have to remove it from the queue and add it again like here? Also Should the method have a return type or not?
{
if (!poolDictionary.ContainsKey(tag))
{
return null;
}
GameObject objectToRemove = poolDictionary[tag].Dequeue();
objectToRemove.SetActive(false);
poolDictionary[tag].Enqueue(objectToRemove);
return objectToRemove;
}```
I did this, is this correct?
wait, so it's not a dictionary?
it is
im using both
queue and dictionary
what why
im using dictionary but applying operations of a queue
dequeue and enqueue
i watched the brackeys tutorial on object pooling
i am almost 100% sure that brackeys did not have a dictionary of queues for his pool
okay, so a Dictionary<string, Queue<GameObject>?
yes
and with your current setup, you aren't even guaranteed to get an active object with the way you are going about it
i literally copied him
prove it. show both your code and link the tutorial
alr
Get Skillshare: http://skl.sh/brackeys2
Speed up your game by setting up Object Pooling in Unity!
● Singleton Pattern: http://wiki.unity3d.com/index.php/Singleton
● Generic Unity Object Pooler: https://github.com/Rfrixy/Generic-Unity-Object-Pooler
● EZ Object Pools: https://assetstore.unity.com/packages/tools/ez-object-pools-28002
❤️ Donate: ...
its working in my game
before i even bother watching that, i'm going to go ahead and guess that brackeys has an objectpool class and has a dictionary of those. and the object pools themselves have the queues because that's really all an object pool needs to be
oh no. i was wrong. and yet i'm not surprised that his object pool is hot garbage
wdym
also unity has its own built in ObjectPool<T> class now
i mean it sucks. the logic makes little sense because you dequeue an object when it spawns, then enqueue it again for some reason? why is the active object still in the pool
because if u want to use it again
u add it back
you put it back in the pool when you are done with it
so u mean it really doenst help with the frame drops im getting?
what happens if you are using a bunch of objects and suddenly start reusing them while those objects are still in use
have you used the profiler to determine where performance issues are coming from?
whats profiler
i was using simple create destroy of many items earlier. And I was getting framedrops. Now I did this object pooling approach, but im still getting performance dips
your DespawnFromPool is named incorrectly, and you're dequeuing (removing) an object from the pool, only to deactivate, and return that same object . . .
so I should make it a void?
huh, what is void??
making it a non-returnable
why would i need it to return something anyways
{
if (poolDictionary.ContainsKey(tag))
{
GameObject objectToRemove = poolDictionary[tag].Dequeue();
objectToRemove.SetActive(false);
poolDictionary[tag].Enqueue(objectToRemove);
}
}
}```
it's called a method not a void. void is the return type for a method that returns nothing
ik
thats what i meant
making it void
that's the whole point of object pooling: recycle to reuse. you remove and activate the object, use it, then return and deactivate it . . .
so wdym when u say its named incorrectly
is it in the code that im doing something wrong or just a naming convention
DespawnFromPool sounds like your retrieveing the item from the pool to use, but you're actually trying to place it back in the pool . . .
i just want to deactivate a gameObject when its meant to be destroyed
and since the code within the method does retrieve an object from the pool (when it's not supposed to), it seems the name confused you as well . . .
{
if (poolDictionary.ContainsKey(tag))
{
GameObject objectToRemove = poolDictionary[tag].Dequeue();
objectToRemove.SetActive(false);
poolDictionary[tag].Enqueue(objectToRemove);
}
}
}```
that seems correct?
why are you using an object pool if you're destroying the GameObjects? a pooling system is meant to recycle and reuse the objects instead of destroying them . . .
i mean, earlier i used to destroy them
but it was causing me performance dip
so now i want to change my architecture
so that i dont have to destroy or create them
about the creation part, I already set up the code
Im just working on deactivating it now
the moment it was meant to be destroyed earlier, it should be just deactivated now
then put back in the queue
for reuse afterwards
the GameObjects that are spawned need a reference to the object pool they belong to. then you can add them back to the pool without searching through the dictionary . . .
they already have a reference as```
public Dictionary<string, Queue<GameObject>> poolDictionary;```
It has the tag string
no, this is the same code as spawning a GameObject from the pool. you're finding the pool (queue) using the string, then removing the first GameObject by Dequeue and deactivating it. this is a different GameObject from the one that is already dequeued (removed) from the list . . .
@wintry quarry so what line of code do you suggest could work as a collision detector
without physics involved
the player has no collider
then what approach do u suggest?
it likely will later on, but then I'll be good enough for a code refactor
What do I use to call the UGS Rest API from Unity?
Also I want to call it from my UGS C# Cloud Code Module, can I use it there too (this is not inside of Unity)
did you dl the Cloud Code package
you can call functions with c# through that
Oh nvm you wrote REST
going through the docs, just found an example, it was hidden somewhere 😛
would I be able to install that in my UGS C# Cloud Code Module as well? (outside of Unity) but it does run on the unity servers
nvm it's also in the docs 😮
when using transform.lookat, the worldup parameter doesn't allow me to use a y axis, I need the capsule to be standing upright like in the 5th screenshot, however I'm only able to rotate it on a 2d axis, which doesn't let me stand the capsule upright. Variables on bottom of every screenshot. How would I solve this? without using transform.rotate on another line since that causes it to flip around when moving past the target on the x or y axis
this is the only code that modifies the rotation of the capsule
The worldup only controls the roll. Most of the rotation will come from the look direction itself
If you don't want him laying down he'll need to be looking at something at his own y height
I can’t just point the y axis at the target instead of the z?
You can, but not by using transform.LookAt
transform.up = targetPos - transform.position;
Ok thanks
@wintry quarry do you have a minute?
You cant have collision detection without a collider
Consider giving the context for others to answer
this and all below @willow scroll
how would I do that?
What's the context of [this](#💻┃code-beginner message) message?
one sec i gotta find it
for example this one
In the context of your grid based movement Praetor already pretty much told you what is the best approach
movement works, not walls
I'm guessing we need more than one line to get the collisions working?
Well, this line sets the canMove boolean to true if no colliders in the box with the size (playerSize, playerSize, playerSize) * 2 were found
Can be also simplified to
bool canMove = !Physics.BoxCast(transform.position, Vector3.one * playerSize, moveDir);
What else do you want to implement for your collisions?
see
there's a big issue with this
which I do not understand as I'm a complete beginner
all these
you are unable to move at any distance on these axis in these directions
as if the boxcast was infinitely long
and hitting corners
which I kinda fixed by scaling the boxcast size down
but the axis issue persisted
nevermind, this doesn't do jack
@willow scroll only thing that comes to my head is that it goes on without limit and it's too big
All these have a script to move them?
How do you move them?
Please, show the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
private Vector3 lastMoveDir = new Vector3(0, 0, 0);
private float playerSize = 2;
private void Update() {
Vector2 inputVector = new Vector2(0, 0);
if (Input.GetKeyDown(KeyCode.W)) {
inputVector.y -= 1;
}
if (Input.GetKeyDown(KeyCode.S)) {
inputVector.y += 1;
}
if (Input.GetKeyDown(KeyCode.A)) {
inputVector.x += 1;
}
if (Input.GetKeyDown(KeyCode.D)) {
inputVector.x -= 1;
}
inputVector.x *= playerSize;
inputVector.y *= playerSize;
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
bool canMove = !Physics.BoxCast(transform.position, Vector3.one * playerSize, moveDir);
if (canMove) {
if (moveDir != Vector3.zero) {
lastMoveDir = moveDir;
}
transform.position += moveDir;
transform.forward = lastMoveDir;
}
}
}
all code so far
you control the player
walls are a prefab model and box collider of precisely the player size
Please, consider using a site to share big code blocks !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.
The issue is definitely in your canMove boolean
As I have previously mentioned, it doesn't allow you to move if your Box cast touches any Colliders
Additionaly, you don't use Time.deltaTime. Perhaps you don't know when you should use it?
it moves 1 grid space at a time
when you press it's a full block size move
grid based everything, at least most mechanics
Oh, exactly
I haven't mentioned you were checking for ButtonDown
Then deltaTime is not required
after the collider crap I plan to add a quick animation where instead of instantly moving the movement is split into 10 frames. I probably will yap about it here as well
Also consider checking for the inputVector not being (0, 0) after the calculations
I can debug log it, where do you need it?
This can also be done via code
ik
Are your talking about the inputVector? It's not necessary now. Do it after you fix the issue.
You may want to debug the BoxCast's out RaycastHit hitInfo if you're wondering what your object is colliding with
public async Task SavePlayerInfo(IExecutionContext context, IGameApiClient gameApiClient, string key, object value)```
IExecutionContext is, as far as I understand, dependency injection to get info about the current call
Is this something I need to include when I call the function from my game client? How?
The float playerSize is also to 2, so your Box's size in the world space is (4, 4, 4)
all box collider
I'm guessing the edges of the box and colliders overlap
If your boxes are 1x1, the Box looks approximately like this
Right
Are you intending on moving your character just when it doesn't collide with the other objects?
I checked, any distance
sometimes that means interactions with immovable stuff, but otherwise yes
What is this supposed to mean?
hey me too
if something with a collider blocks the way we can't move, otherwise, check a bunch of other stuff, like if the hit object is a box
I mean crate
other blocks are planned
Then use OnCollisionEnter and OnCollisionExit to enable and disable the boolean respectively
wh
what and where
Use google if you don't know what they are supposed to do
is this really necessary to make the collisions work?
Do you want your character not to move when any object is on its way, or, perhaps, try to move it, and succesfully do so if the other Collider isn't too heavy?
What do you mean?
I think a switch to check for the type of hit objects is enough, or run a function from the collided objects which if they have will return a value or something the player responds to accordingly
idk, didn't get there yet
Consider also answering [this question](#💻┃code-beginner message)
Also, you can much easier check the type of the object hit using this methods
They're created for this.
no weight, just type of objects. There will be a bunch that respond differently to stuff happening around them. So there will be a special Crate which is a wall but you can push it if IT has nothing in the way blah blah blah
just a way to ask the collided object "Can I go?" and it responds by checking some stuff
let's get the basic collisions down first
I also need to go in 5 mins
Yes. Then use OnCollisionEnter and OnCollisionExit
They should change the boolean canMove, which is not local
OnCollisionEnter -> canMove = false;
OnCollisionExit -> canMove = true;
It's so that these methods trigger every time your Collider collides with others, so you'll, probably, have to store all the Colliders in a list in the OnCollisionEnter and remove them in the OnCollisioExit
I don't really have any more time right now. Can we do this in like 22 hours from now? 8 am for me, idk about you. In the meantime I'll try to plan out as much as I can and then we re-write the code to make everything work. I can't really do later than 8 am, but after 5 am is ok. How's that?
It won't take long
like 10 minutes if I'm not braindead then
I won't be accessible in 22 hours from now. Maybe in 29 hours. Consider asking in the chat and pinging me. If no one helps you, I'll be able to continue the conversation once I'm free.
What time is it for you right now?
I'm gone for a day and night after 9 am tomorrow, so I can talk at 12am the day after tomorrow
It doesn't matter. As I have mentioned, I will be accessible in ~4 hours from now tomorrow. Try my approach and answer to it when you're back. If nobody helps, I'll be able to do so when I'm back
ok
I would consider having 2 methods: OnCollisionEnter and OnCollisionExit.
The OnCollisionEnter should add the objects collided to a list if they pass some sort of check, so are the objects you need. The OnCollisionExit should remove these objects from the list, as the collision disappears.
When you move your object, you want to check for your list, let's call it collisions, being empty. If it's not, the character cannot move.
private void Update()
{
bool canMove = collisions.Count == 0;
// ...
}
private void OnCollisionEnter(Collision collision)
{
if (CheckForAnything())
{
collisions.Add(collision);
}
}
private void OnCollisionExit(Collision collision)
{
collisions.Remove(collision);
}
thanks a ton anyways, see you later
This is the solution you might want to implement. Pinging you for you not to lose it. @magic panther
!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.
My goal is to make the child be in the parent position when it is created, but for some reason it is always created in position 0,0,0!
And where do you see this?
What do you mean?
Well your script has no debugging in it so how do you know it is 0,0,0
My goal is to create a jump animation when the space key is pressed, but every tutorial ive tried following is just confusing me more or ruins my code somehow
I have a walk and idle animation atm and those work fine
This is what I have so far
is there any guide on how can I convert vertex data stored in UInt8/UInt32 to Vector3, Vector4,etc ?
hello
How do I access a bool from another script
Note: the object that is trying to get the bool only spawns when game starts
I need to use the bool in a IF statement
See the pinned messages in this channel. Under General Referencing other scripts
I cant find it
do you know how the data is packed into those primitives?
found it.
unfortunately I don't, what I got is a working mesh file in YAML format which loads in unity and it's other version with the same data but in it's optimized form which I'm trying to make it load.
Never gonna work without knowing EXACTLY how it has been optimized
you cannot deserialize something without knowing how it was serialized in the first place
Hello, im making my first game, 2D topdown game. I used tilemaps to create a room, then to put down furnitures i use tilemaps too (idk if its good practice or not) my question is, i used the custom physic shape on my interiors, but somehow can i delete collider from one tile? If i delete the shape, tilemap collider auto generates back one.
I'm guessing they packed float2 (dropping one dimension of the normal and tangents) at half precision into 32 bits and probably packed the byte arrays at half precision too but not sure because the dev who optimized this files is no more
Actually I also got the same mesh with the deserialized data, isn't there a way I can try different methods until and I get the values in the optimized form and get the method which was used to optimize the mesh
do you not have the serialization code?
how 2 get all objects that have component from static component method?
I'm not familiar with this stuff, I'll ask my team and tell you, but as I know I think we don't have it
Without it, I would say you have a major problem. Without even trying I can think of half a dozen different ways of optimizing mesh data and to try to reverse engineer those by trial and error is not something I would even contemplate
How can an object that doesn't exist in the scene get a bool from another script (the object spawns when the game starts)
where do i put question on how to disable this without disabling gizmos
I have already answered you on another server. Please, consider having a look at the Awake and Start methods I've told you about if you don't know about them, instead of asking exactly the same question on another server and getting the same answer.
Blud I was trying to get an easier way to solve it snice I dont know what the Awake and Start methods are
I googled them and my brain doesn't understand anything
I just started learning unity yesterday, give me a break
then you should !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Could someone help me with my enemy ai behaviour tree:
Im currently facing a problem. the patroling and the Attacking of the player works as intended. The chasing of the player seems to work fine as well. but the enemy cant chase the player breadcrumbs. My player instantiates bread crumbs every .3 seconds. and wheneever the player isnt in line of sight with the player it should chase the bread crumb. but instead of chasing the breadCrumbs of the player it chases the player even though it should be chasing the breadcrumb.
Pastes text or code for online public viewing via a share link with syntax highlighting and an optional expiration period. Supports over 170 programming languages.
they're default methods in unity (the methods that are executed by unity itself) "Unity calls Awake when an enabled script instance is being loaded." and "Start is called on the frame when a script is enabled just before any of the Update methods are called the first time."
The easier way doesn't exist. You won't be able to solve your issue without having a basic knowledge about the basic methods in Unity, usually learned much earlier than finding the variables and Singletons.
Im not sure if someone can answer this but is the best practice when trying to find a specific spawned player prefab for example player 6 in a multiplayer sense but it couls vary depending on scene
Consider asking the questions about the multiplayers in #archived-networking
Ok thx
Gizmos has a dropdown, which allows you to disable the different parts of it, which includes disabling the text icons.
This question may be put in #💻┃unity-talk
I see, you have already been answered there. There was no need in cross-posting.
how 2 get all objects that have component from static component method?
What does it mean?
i need 2 change material for all objects with this component on changing COLOR value
You mean changing the Material's Color?
Because when the child object is created it is at position 0,0,0 at runtime
Alright? Set the Material in the setter
we are ready to perform any try and error to do this, I just need a start at this point. can you suggest me something ?
What from this do i need?
Well, do you want to set the material?
yes
Then why would you need the AudioSettings?
i already have loaded array of materials
Yeah, so you want to set the object's material.
it's tips when i write Set
Why would you write "set"?
And, again, I ask, how do you know this? What are you looking at which tells you this?
It's accessed via Graphic.material
Hi, i set TransparencySortMode to 0 1 0, for my 2d topdown game, but my character goes behind an object before i reach it. If i go to a chair too close from under, its swap behind the chair, and my legs still showing. Whats wrong?
set, material & get r all that i came to mind when i thought how it can be named
Can you DM me the file?
How do I prevent two or more systems that manipulate delta time from interfering with one another?
Material is accessible via Graphic. You should have any Component derived from it.
"Graphics" hasn't definition for "material"
This is the type.
[You should have any
Componentderived from it.](#💻┃code-beginner message)
Graphic doesn't exist in that context
Read the messages I've sent.
This's the type
wdym You should have any Component derived from it?
The same as if you're accessing Rigidbody.velocity
You should have a variable of type Rigidbody
[SerializeField] private Rigidbody _rigidbody;
you mean, that it will be executed 2 all objects that have ANY component?
I mean, your script will change the Graphic's material of the object having it
Hello, i have a question to a project i am working on, I need to store and edit .txt files in a cloud, I am currently developing an app where you can track like your worktime and stuff but everytime I try to store data, i get an path sharing violation error, can anyone help me with that?
If multiple objects have your script, it will change the material on all of them
You'll have to shard your code to get helped
Yes, but its like quit a long code, can i post it here?
Yes, use a specific site. !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.
ok, how 2 access 2 Graphic's material?
Have a Graphic variable first
And you don't have to access multiple graphics.
The Graphic can be gotten with the GetComponent method, as normal components
Yes, that's great.
Please, show the error, including the line.
like this?
No. Graphics is not the same as Graphic
Graphics is Unity's interface for drawing stuff
yes, it is. Graphics exist, Graphic doesn't
Because you haven't included UnityEngine.UI namespace
yes. because i don't need unity's UI, it's for 3d objects
Then don't change the material
can someone help me "fix my bobbing"
void HandleBobbing() {
if (!canMove) return;
if (Mathf.Abs(_rb.velocity.x) > 0.1f || Mathf.Abs(_rb.velocity.z) > 0.1f) {
_bobTimer += Time.deltaTime * (isSprinting ? sprintBobSpeed : walkBobSpeed);
cameraHolder.localPosition = new Vector3(
cameraHolder.localPosition.x,
_defaultCameraY + Mathf.Sin(_bobTimer) * (isSprinting ? sprintBobAmount : walkBobAmount),
cameraHolder.localPosition.z
);
}
else {
cameraHolder.localPosition = new Vector3(cameraHolder.localPosition.x, _defaultCameraY,
cameraHolder.localPosition.z);
}
}
the object that is attached to the camera holder "jumps" whenever i change movement while walking, like from a to d or d to a and so on
https://paste.ofcode.org/izDDwWGjaqWsdpLfJy6yDy The Error is at the bottom
ok, now my chess without materials
Sharing violation on path sounds like you are trying to do something with a locked file
You don't want to access the UnityEngine.UI namespace, so yeah, your chess is without the materials now
So you most likely need to unlock it first, or wait a moment before you read the file
what are you trying to do
This, annoyingly, can also be caused by an antivirus trying to scan the file you wrote
@fluid haven ^
wow, it was with materials
bump
Notice your code opens a stream for the exact same file. My guess is that this must be closed before you try to read it in that method
Hence the cause I mentioned
I don't see where GetEntrysCount is called though
Yes, even before i protet it to the cloud it gave me this error, its just a normal .txt. When i first moved to unity cloud, i used sepreate keys for every entry but if every person has like 300 entrys it extremly slow.
You do have another method ExportEntriesToTextFile which is also async
My guess is that this one has it open
i'm tryimg 2 explain, that materials can be changed without UnityEngine.UI & i need 2 change material for all objects that have my component when i set a velue to static field
I dont really need that, i can try deleting that+
Yes, try that
Or put CloudSaveService.Instance.Data.LoadAsync before you open the file stream and hold the data in memory
So the async code is not happening whilst the stream is open
IDK if this is the root cause but it's worth a shot
I think deleting that already did the trick, thanks very much!