#archived-code-general
1 messages Β· Page 444 of 1
for UnityEvent, the code in TriggerUnityEvent is just doing EventBus.Trigger("UnityEvent", name), which you can do from anywhere
most events go through the event bus so you just need to register/trigger for the right name to use it for your own code
All right, thank you both @thick terrace @hexed pecan I am coming from Unreal Engine and Visual Scripts / Blueprints seem to be much more developed there... Thank you!
visual scripting is kinda new so not suprised its half baked
there's third party ones that can do more stuff like unreal (generating totally new classes etc) but the official VS package is fairly minimal
I mean UE actively encourages and develops blueprint system, whereas unity only got it recently
i got it to work π₯³
just had to set an if statement that resets the velocity of the rb if it falls under the speed variable.
tfw you accidentally use a unity message as a normal method's name π₯²
now to come up with a new name.....
Do you mean me?
What am I doing wrong?
no...? why'd you assume it was you lol
can someone tell me
why its rotated the wrong direction
im using the correct export settings
its only rotating the blender direction when im removing the planes aka leaves
this is a code channel. you probably want #πβart-asset-workflow
oh sry
How to set it up manually by myself?
how tricky is it to modify a value in a prefab variant?
it.. isn't?
If I can get the prefab variant and then just want to change a color or int value in the variant is that feasible
yes
via code I should say
of the prefab?
yeah that's fine
i mean, you can do it
is this for editor code?
or what are you trying to do?
yeah editor code
ah
just a tool to allow people to configure UI objects in the editor
yeah a prefab is just a gameobject captured into an asset, you can modify properties of it or its components just fine
sweet, thank ye
use prefab utility to open the asset, modify it and then save it after
is there really no way to pause an animation or set the speed of a particular state via code?
Each state can use a parameter as a speed multiplier
Select a state and look in the inspector
Set the parameter and change that from code
aaaah ok thank you
that's really clunky
I would have expected a pause and resume method but ok if it works
But wait, will that pause at 0, and resume where it left off at 1?
Naturally yes
guys, i am using text mesh pro and i imported a font, but its showing this random letters. the only working font is, Liberations Sans SDF which was preloaded. im using Unity 6
this is a code channel
thanks for the help mate
if you want an answer to your question, you should probably move your question to an appropriate channel.
#πβfind-a-channel
done
Im using unity 6000.1.0f1 and I just noticed my gizmos are not rendering in game view (when I have gizmos enabled and ticked on) tried restarting but no change
they aren't supposed to render in game view
Gizmos are used to give visual debugging or setup aids in the Scene view.
yes they are, you can enable it
I can do it in 6000.0.37f1 right here next to it
its this in gameview mode
I guess many dont realise its been a thing for a long time but seems broken in the supported version
Hmm try resetting the layout
That has solved similiar bugs for me
its just a wiresphere, I can see it in scene view mode but I would usually be able to see it (when toggled) in game view too its just not working in this version
def something wonky with this ver for me
Can you show the code for it? Maybe it's not where you expect it to be? Maybe something changed around it and the sphere isn't getting drawn?
Or is it that they are visible in scene mode
but not in game mode when enabled?
I can see it fine in scene view, its the game mode thats not showing them when enabled
I have an older version editor side by side (last LTS) and it works in that
Okay, not likely code related then
Definitely sounds like it could be a Unity !bug
πͺ² To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.
π If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click βReport a problem on this pageβ!
π‘If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.
For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting
I'd try the ol' "I have no idea what the fuck unity is doing" solution of deleting the Library folder and restarting?
I'd also check if the bug is present in a fresh scene
And maybe toss a debug.log into the gizmo drawing method you are using
yeah its just a simple Gizmos.DrawWireSphere(transform.position, 0.25f); in the OnDrawGizmos. nowt exotic - will try in a fresh scene but its not really got much in yet
same in blank scene, reported bug anyhow
I opened it in the LTS and it works as expected
its just the gameview in supported not working correct with gizmos it seems
there is nothing to log, it gets called - can be seen in scene view
ensure it is still being called when you are viewing game view by logging
If the actual object drawing the gizmos gets culled due to being out of frame or occluded, do the gizmos it draws get culled as well?
Maybe due to some different settings the play camera is culling it? Maybe it's on a layer the game camera can't see?
i'm trying to make a system in unity which takes two meshes, and takes the overlapping components making it a seperate mesh which is the volume intersection of each other
i'm using LibCSG library to attempt and achieve this, however it hasn't worked out. Does anyone have any say starting point to start making this? there can be any number of "LIGHT_" components, and they can only intersect with other "LIGHT_" components at any time, as they are movable.
using UnityEngine;
using System.Collections.Generic;
using LibCSG;
public class LightIntersectionManager : MonoBehaviour {
public Material intersectionMaterial;
private List<CSGBrush> lightBrushes = new List<CSGBrush>();
private CSGBrushOperation CSGOp;
private CSGBrush IntersectionComponent;
void Awake() {
CSGOp = new CSGBrushOperation();
IntersectionComponent = new CSGBrush("IntersectionComponent");
foreach (var mf in FindObjectsOfType<MeshFilter>()) {
if (mf.gameObject.name.StartsWith("LIGHT_")) {
CSGBrush lightBrush = new CSGBrush(mf.gameObject);
lightBrush.build_from_mesh(mf.gameObject.GetComponent<MeshFilter>().mesh);
lightBrushes.Add(lightBrush);
}
}
}
void Update() {
/*
* Check for intersections between all objects with "LIGHT_" in the name
* create a mesh which is the intersection between any two light objects
* give the mesh: intersectionMaterial, kinematic frozen rigidbody, mesh collider
*/
}
}
FYI, that is called a boolean AND operation or boolean intersect operation
In case you want to search for other solutions
boolean intersect i believe
most solutions i found of people attempting the same use CSG libraries such as this one
Godot has an implementation of that somewhere in the source probably
i also heard of triangle-triangle checks im not sure if that would be better
Are these 2D (planar) meshes or 3D?
3D
Triangle-triangle check is kinda vague
i can send an image to better illustrate my goal
In any case you want a boolean op
Wonder what blender does, but it's usually messy and populates a ton of verts in the end
Which might/probably does use some triangle intersection checks
that little triangle bit which is inside the yellow part would make a mesh ideally
the cube is movable
i'll check that out
Probuilder also has a boolean tool but it's experimental probably forever because it seems that no one can make fully robust boolean operations
Not sure if it's exposed in an API anywhere
good concept though for level building and blockouts
assuming you can clean it up
probuilder could really integrate more of it
I wish I could use that tool more, but it seems to brick itself if do some bad operation
Just out of curiosity, since accessor modifiers aren't really a thing by the time stuff compiles, Is there anyway I could brute force inheriting from some of Unity's sealed components?
Probably wouldn't be for any long term solution just playing around with things
I return, I fixed the gizmos not appearing in game view.. it happens when DX12 is selected
switch to 11 and it shows... annoying but ok
(in the supported release)
make sure to submit a !bug report
πͺ² To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.
π If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click βReport a problem on this pageβ!
π‘If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.
For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting
aye I did earlier, going to update it if I can
Just looking for a general vibe check I guess but for a prototype im making I wanna make a fairly generic object viewing/setting window for content in the game that's going to be pretty similar to Unity's inspector. Right now the way im thinking about doing it is having each piece of content provide a list of boxed paired getters and setters for the values they want shown and changed and then check the type of the value and see if I have any UI options that can support editing that value. Am I kinda on the right track here?
https://gist.github.com/IAmBatby/06f7f194aa5c091f6008e70812f2d5f8
I've thought about using some kinda boxed/wrapper class for the values I want to showcase directly that's serialized but holding off for now. I might need to pivot for that if i get into needing to provide extra data like display text and whatnot
I am generating UI elements procedurally, so I'm not sure how this is done
titleDisplay["fromLevel"] = new IntVariable { Value = fromLevel };
Ooh, ok I'll give it a try, thanks!
or preferably
titleDisplay.Add("fromLevel", new IntVariable { Value = fromLevel });
I really struggle to have a working dayCycleSpeed using the dayCycleSpeed field in the VoxelPlayEnvironment class but it doesn't work, it always goes too fast. So how can I fix that please ? Maybe my formula in TIME_INCREMENT_PER_SECOND is wrong, if that's the case what's the correct formula please ? π€
you would have to first explain/express what you want this value to actually do/mean
What does a "daycycle speed" of 1 mean? What about 5?
I will say one issue i'm seeing for sure here is that you're not using Time.deltaTime in Update so everything is going to be framerate dependent - i.e. it will run faster with a faster framerate, which is generally not desirable
you're doing += TIME_INCREMENT_PER_SECOND every frame
pretty sure you want to multiply by deltaTime there
In my case 1 should be normal speed meaning my time scale between IRL and In Game Time (IG) is 1s IRL = 1m IG
that will make it actually behave as though it's "per second" and not "per frame"
Yeah tried this it's better in terms of speed but it feels like there's a desync between the time and the visual part (moon / sun) rotating but I'm not sure π€
If you want 1s = 1m then TIME_INCREMENT_PER_SECOND should be 60 (60 seconds in game per 1 second IRL).
And yes you need to multiply bt Time.deltaTime
why'd you get rid of the TIME_INCREMENT_PER_SECOND thing here
so like this ?
it's backwards
should just be 60
not 1/ 60
and you shouldn't have dayCycleSpeed being used in update
why ?
just timeOfDay += Time.dletaTime * TIME_INCREMENT;
you only needed that to calculate the time increment
there's no sence factoring it in again
I use the slider in the inspector to make time go faster or slower π€
but you told me that it equals 60, why is it now equal to dayCycleSpeed ? π€
you have too many variables here - it's confusing and overcomplicated
because you should be setting it to 60 in the inspector
if you want the game to run 60X faster than real life
which one ? TIME_INCREMENT_PER_SECOND or dayCycleSpeed ? Because TIME_INCREMENT_PER_SECOND isn't Serialized and dayCycleSpeed is limited between -10 and 10 (didn't write its script and I don't understand why they allowed negative numbers there) π€
So is this your script or isn't it
Again back to the very first question I asked you here: #archived-code-general message
you can and should make it how you want it to be
don't be constrained by whatever the code was especially if it was written by someone else
The one I'm showing picture is mine yes, but VoxelPlayEnvironment where I get that dayCycleSpeed isn't my script but the one from the asset I bought
why would you constrain it to -10 to 10 if you want 60?
So we go back to the quiestion of you have to actually explain what you want the number to mean
without deciding that we're just grasping at straws in the dark
I'm talking about "dayCycleSpeed" in the inspector coming from the VoxelPlayEnvironment
yes you have to say what you want that to mean
I'm confused
if you want it to be such that 1 means 60s per real life second, then you would need to multiply it by 60.
e.g. TIME_INCREMENT = dayCycleSpeed * 60;
yes that's what I want by default when dayCycleSpeed has a value of 1
then if you set it to 10, it would be 1 second in real life = 600 seconds in game (10 minutes)
huh no, that's not what I want
I want when I set it to 10, it goes 10x faster, meaning the value is really low between each iteration
10 minutes IS 10x faster than 1 minute
huh, what ?
How is 10 minutes faster than 1 min ?
10 minutes of game time per second vs 1 minute of game time per second
it's faster as in the in-game clock is running faster
I said it here
and then you need to fix the first line of Update too
Like I said here
like so ?
but there will still be an issue of me not being able to change speed of day at runtime as "dayCycleSpeed" is assigned at start
your code assumes that timeOfDay is a number between 0 and 24
also that if (timeOfDay > 24) timeOfDay = 0; line is not right - it should be timeOfDay %= 24; really
then we can just do the calculation in Update
float timeIncrementPerSecond = voxelPlayEng.world.dayCycleSpeed * 60f;
timeOfDay += Time.deltaTime * timeIncrementPerSecond;```
and get rid of the stuff in Start
the other thing though is we'll need to adjust to your 24 thing
still need to keep timeOfDay as it's the starting time of day that the game starts at
I want my game to start at 6:00 AM and not 00:00
anyway the code I gave you assumes timeOfDay is expressed in seconds
and there are 86400 seconds in a day
but you want it to be expressed in hours
so we would need to divide by 3600
But wait %24 I already do that here, isn't that enough that I have to put it again in Update() ?
e.g.
float timeOfDayInSeconds = 0;
void Update() {
float timeIncrementPerSecond = voxelPlayEng.world.dayCycleSpeed * 60f;
timeOfDayInSeconds += Time.deltaTime * timeIncrementPerSecond;
timeOfDayInSeconds %= 86400; // wrap the day around midnight
float timeOfDayInHours = timeOfDayInSeconds / 3600f;
}```
well your days calculation doesn't make sense since you're automatically setting anything > 24 to 0 anyway
to be perfectly honest you could/should just be using DateTIme.
how would you manipulate DateTime class to make it go faster ?
and make it start at day 0 ? And at hour 6:00AM ?
wouldn't a TimeSpan make more sense than DateTime since they don't appear to need an actual date?
DateTime currentTime;
void Start() {
// assuming january 1st, 2025 here
currentTime = new DateTime(2025, 1, 1, voxelPlayEnv.world.timeOfDay, 0, 0);
}
void Update() {
float timeScale = 60 * voxelPlayEng.world.dayCycleSpeed;
currentTime = currentTime.AddSeconds(timeScale * Time.deltaTime);
}```
like this^
maybe
why 2025,1,1 ?
ok but that does mean that it takes a starting IRL date ?
yes
why ?
because that's what DateTime represents
So that means it will never start at day 0 π€
if you don't need an actual date, just use a TimeSpan, you can even format it to give you Days:Hours:Minutes
I'm interested to know how please
Here's how you would with TimeSpan:
TimeSpan currentTime;
void Start() {
currentTime = new TimeSpan(0);
}
void Update() {
float timeScale = 60 * voxelPlayEng.world.dayCycleSpeed;
currentTime += TimeSpan.FromSeconds(Time.deltaTime * timeScale);
}```
Easy enough to read from too
string currentTimeString = $"Days: {currentTime.Days}, Hours: {currentTime.Hours}, Minutes: {currentTIme.Minutes}, Seconds: {currentTime.Seconds}";```
there's probably a nice way to use format strings with it that I'm not savvy to as well
so I don't need my FloatToMilitaryTime() anymore ?
nope
also calling it "MilitaryTime" is silly, it's just a 24 hour clock which much of the world uses already
well you might replace it with something like this^
Not really, the US don't use the military time writing, they use the 12 Hours Clock System and use the suffix AM or PM, that's why I called it military time
because it's wrriten as a 24 hours system
like for instance 2200 = 22h00 = But the US say 10 PM
sure, it's not standard to use the 24 hour clock in the US, but still calling it "Military Time" as if it is exclusive to the military is silly and a thing that only americans do
anyway - point is - Use TimeSpan, it's nice
I suck at coming up with name for variables and methods π€£
Now deleting this method βοΈ puts me in trouble for this system π¬
oh gosh
pretty sure that wasn't going to work anyway
it depends on exact times being reached
it was working at some point
yes, that's what I need
the way to do this would be to have a list of events with times attached to them, and whenever the time changes you iterate over the list and trigger all events whose time is less than the current time
to start and end routines
and remove them as you trigger them
no as it will create a big problem which is it will trigger all my previous routines too
and I don't want that
I'm not sure to understand
it's ok this is a totally separate issue anyway
I have no clue
it says there
it says time in 0-24h range
no above you have a float
oh - yeah it wants the hour of the day
you can do currentTime.TotalHours % 24
well you'll need to actually do
(float)currentTime.TotalHours % 24f```
It's really slow, how can I be sure that 24 minutes IRL = 24 hours IG ?
Also can I put back my system that avoid printing the same value multiple times ?
but I will need that anyway later to avoid Invoke the same event multiple times
honestly - is it an actual issue?
yes you can of course make a system for that
but I don't see that it would be an urgent need
Yes as I will need to enable / disable areas in the prison at precise timings
anyway the actual time won't bee the same anyway
the precise timings thing is a pipe dream and it will cause bugs
if you have a framerate hiccup that makes you skip a second, your event will not trigger
you should use a more robust algorithm for it
like ?
like I mentioned above - triggering the event at the first time you see the current time is >= the scheduled time
Isn't there a better way than that ? Like maybe not using framerate stuff and go for more precise stuff ?
not sure what you mean by that
you are bound to the framerate of the game, you don't have any choice about that
you could use FixedUpdate but that's really just a wrapper around Update doing the same kind of check I'm talking about
I guess if you don't feel like thinking about it, FixedUpdate is one possible choice
What about IEnumerator ?
Coroutines?
yeah
no, coroutines are not going to help you with precise timing
they do the same thing I was mentioning
don't those give precise timings when you yield new WaitForSeconds() for instance ?
no
not at all
if you do WaitForSeconds(1) it will run on the first frame after 1 second has elapsed
which will never be exactly 1 second
it will be like 1.0154 seconds or something
coroutines are checked once per frame
There's really no escaping the frame-based game loop
mhh interesting, so your solution with >= is the best I guess ?
I wouldn't have given you my second-best idea.
And is that the way it's done in published games too ?
absolutely
interesting, you taught me something new today π
they should renamed that method from the coroutine to WaitForApproximativelySeconds() to be more accurate π
That's true to almost everything time related in unity(and most other game engines)
Unless the whole logic is run on a separate thread and does something like thread sleep or yields. Which wouldn't be 100% precise either, but probably precise to the microseconds(depending on how busy the CPU is).
the fact is you can only draw things on screen when a frame happens anyway, so there's not a huge benefit to trying to do things outside of that.
when I set the speed to 20, it skips values, is that normal ? π€
is it the thing we talked about just above ?
We would need to see your current code to say anything
yes it is normal and expected
with speed set to 20 time is moving 1200x faster than real life
Please share !code properly next time:
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
private void Start()
{
voxelPlayEnv = VoxelPlayEnvironment.instance;
timeOfDay = voxelPlayEnv.world.timeOfDay;
currentTime = new TimeSpan(0);
}
private void Update()
{
float timeScale = 60 * voxelPlayEnv.world.dayCycleSpeed;
currentTime += TimeSpan.FromSeconds(Time.deltaTime * timeScale);
voxelPlayEnv.SetTimeOfDay((float)currentTime.TotalHours % 24.0f); // Set Time of Day
print($"{currentTime.Days}:{currentTime.Hours}:{currentTime.Minutes}:{currentTime.Seconds}");
//OnGameTimeChanged?.Invoke(timeOfDay); // Call the event
// previousTimeOfDay = timeOfDay; // Set the current time to the previous time to avoid events firing multiple times
}
the indentations is messed up on discord π€
60 years since the creation of discord and something this simple is still not fixed π₯²
the indentation is fine - you just started your copy paste from the p so it doesn't have any preceding space on the first line
fixed it π
public abstract class InspectorField<T> : InspectorField
{
public override bool TrySetTargetValue(BoxedValue potentialValue)
{
if (potentialValue is BoxedValue<T> castedValue)
{
SetTargetValue(castedValue);
return (true);
}
return (false);
}
}
I can do generic type checking like this right? where if the InspectorField<T> in question is a InspectorField<string> and the BoxedValue<T> is a BoxedValue<string> ?
the answer is yes
@leaden ice @cosmic rain @somber nacelle Thank you to all of you π π
Hi all,
is it okay to subscribe to an unity event of a prefab with another prefab? like a preconfiguration. i feel like i got crazy bugs in it that i cant even debug.
no
prefab assets shouldn't have event subscriptions afaik
unless it's correctly in the context of it's own asset
posting relevant screenshots might help
thx keep in mind i used a unityevent in an SO before and it worked but i wanted to try something different
i can try post screenshots
not sure what to show coz i cant find the place where it fails
π
Oh if you wanna post code, see !code π
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
aight
so i should send my files?
A tool for sharing your source code with the world!
1 enemy should send 20 xp per death. the player always has 0 xp at start.
and if i kill 7 enemies it instant starts with 140xp and then adds normaly 20 per death
but it should look like this: 0, 20, 40, 60, 80, 100, 120, 140
i stop the game and restart and kill 4 enemies and get this
last screenshot π then i kill again 5 and got this
i could also join a voice channel where i share a screen. thx anyway
don't have those, kinda breaks the point of community support
Ah makes sense
First thing I noticed that you are calling this in Start: cs UpdateExperience(0);
Which adds 0 to the XP. Do you expect it to set it to 0, or are you calling that just to invoke the OnExperienceChange event?
I also don't see how prefabs are related here/why are you using or invoking events on the prefabs
Sounds like hell
The whole thing is about communicating with objects that will get instantiated in the middle of the game
I try to find solutions, but its so hard to not have a reference of another gameobject to call the methods that i need
Okay so not really prefabs, right?
Prefabs mean gameobject assets, we don't use "prefab" to describe an instantiated object
ehhm im not sure. i instantiate enemy prefabs and a player prefab into the scene. what is it called?
Yeah at that point it's called just a gameobject or an instance
I'm not trying to be pedantic, just making sure we are on the same page :p
yeah sure np ask everything. this bug keeps me up all night
usually prefab asset vs. prefab instance
so i just want to update the gui with Update experience at the start
Yeah that makes sense, just making sure
OnExperienceChange gui is subscribed on that
I guess I don't understand this part. What happens between the 0 and 140 xp logs? You kill 7 enemies?
"It instant starts" is confusing to me
yes i kill 7 enemies with one shot
where are you subscribing to OnEnemyDeath?
I only see UpdateExperience being called from the start, where else do you call it from?
i dont see any subscription to OnEnemyDeath aside from supposed commented code
it's subscribed to its own event?
Is that all that OnEnemyDeath does?
yes
i have another ondeath event in a health script that does way more earlier ofc
thats why i got confused at first
Ahh so the issue is that this event on thet enemy object calls a method on the player prefab?
so wait you're sending an event to instantiated objects OnEnemyDeath during runtime?
is enemylevelcontroller for a single enemy or the controller for all enemies in the level?
thats what i thought too
enemylevelcontroller for all that got instantiated
so each enemy has enemylevelcontroller?
But what does this belong to
yes
Hey I was told to come here to learn codingβ¦
The player level controller script
mage is the player
The prefab or an instance
i kind of know what the problem is but dunno how to properly say it ahahaha
i guess the others know too already xD
so when an enemy dies you get xp from them, and your problem is that you're getting too much xp?
I think the event is calling UpdateExperience on the player prefab, not the instance
basicly
do you kill only one enemy or all of them at the same time?
the playerpref in my directory so to say?
oh
all with 1 fireball at the same time
Yeah so that's not the same object as the one you instantiate into the scene
The prefab is the blueprint/template that you use to instantiate new objects
i guess what he did is create a prefab for the enemy and player. then uses the prefabs to the event thats why it shows.
You shouldn't reference the prefab and call methods on it
then it makes sense no? OnEnemyDeath calls an event that increments player XP, if you kill all of them at the same time then your xp goes brr
It doesn't know to use the player instance in the scene instead
I assume you mean the prefab asset in an assets folder?
no it doesnt coz u should get xp one by one. and i just get the xp for all at the same time and THEN it starts with giving me the xp one by one also!
yes
okay so what i understand is you want to kill all of them, but get xp one by one
instead of getting everything at the same time
complicato
can you check:
go to your enemy prefab. then click on the mage (Player Level Controller) of the event. tell us what it pinged in the editor.
make sure yuo are not in play mode.
it starts with 140 experience for no reason. i just had 0 and now i got 140 from killing 7 enemies but that cant be the case because if i debug, it just starts right after to give me the experience for the first kill
sad that theres no call or something channel in this server xD
Because you are sending XP to the prefab and not the instantiated object.
You are instantiating the Mage into the scene, right? (Or have it in the scene to start with)
yea this might be the problem
i instantiated for this case
you need to reference the instance
yeah it could be the case
you instantiated but you are still using the prefab
PlayerMage mageInstance = Instantiate(playerMageObject).GetComponent<PlayerMage>();
something like this gives you the instantiated script of the object
You need to pass the player reference to the enemy when the enemy spawns
Or in some other way you need to have the player instance referenced in the event instead of the prefab
but what if the player needs to know the enemy? there are 100 enemies and i need exactly one
you can pass the enemy gameobject through the event
whatever reason the player would need to know a specific enemy would involve that communication
you could have an enemy identifier, like an index or a certain name, whatever you want, send it to the player and have the player check if its the enemy you want
if you have just one player. for now you can make the player controller as singleton.
then create an enemy spawner object. in your enemy spawner object, everytime you spawn an enemy with EnemyLevelController you reference the player.
var enemy = Instantiate(enemy);
enenmy.OnEnemyDeath(player.SendExperience);
dirty code but that would work for now.
need to think about that π
I donβt want to be a bother but um can somebody teach me coding?? I was told to go here
or a singleton EnemyManager, that references the player at Start() in the main menu, everytime you spawn an enemy you can already send the player reference through it
centralized and clean
Check the reaction you got in the other channel π
if i'm the one doing it, and i want to decouple things, i'll use like an event bus or something. basically, enemy just invokes on enemy death without caring whoever gets it and player just listens to any event that happens.
also i'd recommend C# events, at least for me its way more intuitive
the one i'm talking about is different from unityevents where you need the actual reference.
i just refactored all c# events to make use of unityevents
Yeah, unity events are more for when you need to assign it in the inspector. Which they can't do in this case because the enemy and player are spawned at runtime
coz i want the game designer to decide whats going on without have to go to the code
yea feels stiffer, C# events you just rawdog it with code
When does the player need to know the enemy?
then i'd make a file showing the entire system you're creating
if the game designer wants changes then they just refer to that file
basically it would be like this in enemy:
EventManager.EmitEvent(OnEnemyDeath);
then in player you just subscribe:
EventManager.Subscribe(OnEnemyDeath, OnEnemyDeath);
void OnEnemyDeath(Enemy enemy) {}
debatable
are you the game designer?
you aren't either what
i said debatable because i don't think a good amount of people would agree with that advice
ohh i see
not saying its wrong but not like a standard goto solution
it would depend if the game designer knows how to code
gets popcorn πΏ
What do you mean with this?
he said this
i assumed he wants to make clean code so the game designer knows what's happening
without checking the code itself
he'd look at the unity editor and know
the point of unity events is to avoid code entirely
I don't understand what the designer could change here in the first place
this might be rude, but if he's a beginner, he should not think about that yet :x
yes and i feel its nice
i think im not a beginner but not an expert either
Personally, I didn't gauge you as a beginner π€·ββοΈ
but like Osmal said using UnityEvents with instantiated gameObjects during runtime isnt practical
are you singleton pilled proto
@ocean mirage ^ What do you need the designer to be able to change?
ok. lets just say that if you cant differentiate or know the limitations of prefabs and instances, then i guess you still have a lot to learn. and making code that a designer can use is probably not one of them YET
Because I think this should all be hard coded
yea i'd recommend focusing on getting the system working, and then cleaning it after to make it more readable for other people
for now, just tell your designer that he can only change the data values in scriptableobjects. and if he wants custom mechanics, just tell you, the developer.
i actually knew the differnce between it but i thought the event makes no difference about it thats why i tried it
thanks all
u helpd me alot
one nice comprimise is using a scriptableobject to middleman these kinds of requests if you want a mix of writing code and exposing it to game designers
eg.
public class PlayerReference : ScriptableObject
{
public void AddExpToPlayer(int value)
{
MyGameManager.Instance.Player.AddExp(value)
}
}
then you can pass this into the unityevent and as long as your singleton manager is setup correct and has a proper reference to the instanced player your gucci
good compromise but somehow adds redundancy so I don't like it xD but it's probably just me :x
far from perfect but imo a good balance between ease to setup for programmer and ease for designer to use
Seems kinda shit to me, editor validation and automation are the way to go to make sure things work correctly if set up by others.
editor validation and automation
but how?
its going to differ per project but if some component needs to be initialized/referenced somewhere when added, it can be done automatically in some way
I prefer to init and handle dependencies such as player, config, localisation manually without static singleton references
i dont understand exactly how u would do it but maybe chat gpt can help me with your ideas
i dont like singletons either
It can be useful to just use a static field but there may be a time when you wish to use something elsewhere and that field is no longer usable.
To avoid this you probably need the manager to initialize objects and give the references they need on Init or pass itself so they can ref this way.
e.g. Load scene -> init manager -> manager inits children and gives dependencies
with that approach i cant really use unityevents right? i need to go back to c# events
If the event needs to reference a scene object then yeah, you need to might as well use C# events
Really depends on project experience and team scope imo
unity events can be subscribed to with code but yes something not in the scene to start cant just be used
You probably need components ready made to perform the tasks you need without unity event stuffs
remember you can do whatever you want you dont have to listen to me π
so in order to not have a reference of something u want to subscribe to, best thing u could do is having multiple event managers for different things
why is there not a better solution to that overall? maybe im blind or stupid π
i feel like programming in unity is kinda easy as a software developer but the architect stuff is way more confusing than in real life projects with spring, dotnet or other frameworks
im stuck so hard with this event stuff and i only want just a single solution to that, so i can keep going. coz the normal stuff like making new gameobjects and content is kinda easy
just ignore my cry sorry π
thx all β€οΈ
I'm not fully understanding your use case rn but hopefully you get a solution you like.
hey guys whats a nice and clean way of having the player with a trigger collider and everytime it goes through a spawn point it picks up that gameObject and sends it to a list?
right now i got a waveManager that contains a list of all the available spawnPoints close to the player
and with that player trigger i want to either add or remove from that list everytime they get close or far
are C# events good here? or would it eat too many resources?
I think thats fine. The player would have an event that is invoked when it hits a spawn point?
yea
It could also be the other way around, the spawn point detects the hit and then tells the player to add itself
May be better as im not sure how reliable a moving trigger would be
true and also another thing
this player and waveManager are singletons, so maybe a simple reference is also good? or not a good practice?
c# events are much better than unity events (as the inspector made subscriptions use reflection)
If the spawn point has the trigger collider, it can get the component and add itself without external references
only thing is i'll be adding the same script to all spawnPoints
ofcouse
i'll have quite a lof of spawn points so maybe its better if its centralized
but could also work well
you have many gameobjects anyway so i dont see a problem
If there is 1 component that manages all of the spawnpoints for later use then that sounds fine to me.
e.g. when spawnpoint detects player, adds itself to some list with a unique id . player dies, level manager gets finds best spawnpoint with an id and does something.
If ids are used then this data can be saved and re loaded later
There are many ways to do things so have a think about your requirements and what will be best to maintain and handle in the future
its just a simple way so enemies dont spawn all over the map, but only close to the player (depending on the trigger size)
dont think it needs to be that complex
yea sounds right
Ah in that case you can probably just do a simple square distance check every x amount of time to update some pre sized collection of these points
(squared distance is cheaper to use as we avoid a square root)
https://docs.unity3d.com/ScriptReference/Vector3-sqrMagnitude.html this explains this in more detail
np. Id go with this as using triggers seems overly complex for what you described
this presumes though this is a radius check, a box/rect check is also cheap as its a simple min max bounds checking
{
CrouchInput.Toggle => !_requestedCrouch,
CrouchInput.None => _requestedCrouch,
_ => _requestedCrouch
};```
If I have something like this and want to let the player to swap between toggle crouch and hold crouch, would it be good I make a separate `_requestedCrouchStyle = input.CrouchStyle switch` to dictate the swap or is there a more efficient way of implementing this
void Aiming(InputAction.CallbackContext context)
{
if (context.performed)
{
isAiming = true;
crosshairImage.sprite = crosshairFull;
LeanTween.scale(crosshairRect.gameObject, new Vector3(0.15f, 0.15f, 0.15f), 0.3f);
aimWeight = 1;
} else if (context.canceled)
{
isAiming = false;
crosshairImage.sprite = crosshairEmpty;
LeanTween.scale(crosshairRect.gameObject, new Vector3(0.1f, 0.1f, 0.1f), 0.3f);
aimWeight = 0;
OnShootingCancelled?.Invoke();
}
}
ignore the shitty code but this is how i do it
context.performed and context.canceled
lmfao
so just change the code into something like if(crouchChange.performed) and wrap the same code over
eh sounds not bad
works perfect for me
ight thanks
you can use local functions if you want to not repeat code in a function
{
_requestedCrouch = input.Crouch switch //CrouchInput is a struct
{
CrouchInput.Toggle => !_requestedCrouch,
CrouchInput.None => _requestedCrouch,
if (_crouchSwitch && InputActions.Crouch.WasPressedThisFrame)
{
CrouchInput.Hold => _requestedCrouch
}
else if (_crouchSwitch && InputActions.Crouch.WasReleasedThisFrame)
{
CrouchInput.Hold => !_requestedCrouch
}
_ => _requestedCrouch
};
}```
something I've cooked up haven't tested it yet
what exacly is the use of node scripts, up until now i only use them as some sort of storage of couple values, and pathfinding
found an ok video player for unity, but it comes with all these extra assemblies. Is there a way to chop these down or bring them in to one?
if you want to break it sure π
its normal to split things up in to many assemblies, i use about 8 for my in project stuff
I guess I'll have to get used to it hah
normally I just do new projects in a separate solution and build the dll's/drop them into my project. Then I can manage cross project references outside of unity and not bloat the solution manager with dozens of projects
its not bloat but what made you want to make things outside of the editor?
the projects in the sln dont actually mean anything to unity and are there to represent the different assemblies untity compiles
There's some advantages to building outside the editor and dropping them in. You can version things, and at some point decide to not support a certain project anymore without breaking it--essentially han soloing it to sit frozen until the bytes rot on the last hdd it's on
packages can do this but if this is some lib that is not meant to be unity only, i can understand developing it externally
I met up with some of the Unity reps last year and they actually said that was a recommended action to do--which surprised me. Mostly because they had made a recommendation at all.
good for them but im not going to do this π im fine with packages for such tasks
Hey all! I'm getting this error and I'm not entirely sure why it is. Its pointing to this function:
private void OnTriggerEnter2D(Collider2D collision) {
if (collision.TryGetComponent(out EnemyBase enemy) == false) return;
if (enemy.TryGetComponent(out HealthComponent enemyHealth) == false)
return;
enemyHealth.TakeDamage(bulletDamage);
penetrationCount += 1;
if (penetrationCount >= penetrationAmount.Value) {
_projectilePool.Release(this);
}
}
and I'm really not sure why it's happening
You don't have any protection here for double releasing
OnTriggerEnter2D can run more than one time per object in a single physics update. For example if multiple colliders are entered in one physics frame
you would need some kind of like "isDead" variable to set and use that as protection here
ooh that makes sense
like if this is a bullet and it hits more than one of the enemy's colliders at once
it can happen
I guess an int counting the amount of times OnTriggerEnter2D() was run would be enough?
That could be a little complex because you'd need to reset it in FixedUpdate
oh true
Overkill. Since you can only ever have one interaction, you don't actually care whether it's 2 or 20, all you'd need is "More than one"
Or - I guess if this thing can only ever hit one thing...
You really just need a bool tbh
unless it is supposed to hit multiple things
I do see the penetration count thing?
Couldn't you just use penetration count here?
e.g. change penetrationCount >= penetrationAmount.Value to penetrationCount == penetrationAmount.Value
that would probably fix it too
I'll try that and see if it works
thanks a bunch
In a minute of playtime it didn't happen yet, so I'm guessing its fixed! Thank you
What should I put in the case inside the switch statement please ? I tried to use time. but nothing appears so no .Hours or .Minutes showing up, same thing with TimeSpan.
you would probably have existing instances for that?
Instances of what ?
of TimeSpan
but you could make new ones via its constructor i suppose
alternatively you could get the Hours component and switch on that? idk what you're trying to make
yes there's an existing instance
it's the parameter to this function
but this problem won't be solved by a switch alone
no, i mean for the thing to match against in the switch
oh - yeah - you could do it that way
or just have each one have a time of day expressed elsewise.
.Hours and .Minutes definitely exist on TimeSpan though so IDK what @fiery steeple is saying
Like I send it in this event here, but I'm confused why here (so in another class) I can write currentTimeOfDay.Hours, etc... while in the other class I can't π€ ?
wdym you can't?
You can see all the properties here https://learn.microsoft.com/en-us/dotnet/api/system.timespan?view=net-9.0#properties
Yeah what is stopping you?
probably because you're in a switch statement?
doesn't show up π€
because that doesn't make sense
@vestal arch βοΈ
it would be like switch (time.Hours) { case 5: }
so I can't do that in a switch statement ? π€
Oh
you need constants for the switch cases
but this is really not going to work well as a switch
oh yeah because of the thing we talked about yesterday, aka the imprecision ?
yes
so I have to go throug a classical if statement ?
I don't understand π€
then one way you could do this is like:
// declared outside
HashSet<Event> alreadySeenEventsToday = new();
foreach (Event evt in allDailyEvents) {
if (currentTime.Hours >= evt.TimeOfDay && !alreadySeenEventsToday.Contains(evt)) {
alreadySeenEventsToday.Add(evt);
ProcessEvent(evt);
}
}```
where you put all the events in a list called allDailyEvents
effectively we would be checking all the events to see if the time of day they happen at has arrived yet, and if it has, put it in a set to track which ones we've seen today (so we only process them once per day), and process them
so basically if you had like:
{
name: "breakfast",
timeOfDay: 6.5 // 6:30am
},
{
name: "lunch",
timeOfDay: 13 // 1pm
}
]```
then lets say 6:30 rolls around, the current time might be like 6.55 (this is what you'd get from currentTime.Hours). So you would see that breakfast happens now, and you would add it to the set of things you already saw so you would ignore it going forward.
A switch statement only checks ==. You are checking if time is equal to a specific thing. The thing you put in the case needs to be something that time could be == to. You can't use any other comparators for a case
you can though? and TimeSpan implements the necessary operators
It doesn't matter what TimeSpan implements. A switch statement literally just checks equality
You can use > and whatnot for a timespan, but not in a switch statement
that's what the base switch statement is. some languages like java, c#, python have pattern matching where you can do more than just equality
Is that available on the version of C# that Unity uses?
yeah, just tested
It looks complex I understand nothing π₯²
At one point I remember lamenting that I couldn't use the inline switch statement, but admittedly that was a while ago...
uh, that's a switch expression?
I just assumed nothing ever improves and that we were stuck without them forever
fair given the state of the runtime situation lol
I wrote an explanation after the code...
even with that it's hard for me to understand π First question I have is about the "Event" keyword, is it mendatory to be "Event" or is a specific Event that I need to create or a name of a class ?
Remember when I wrote this?
I'm talking about this
Yeah, so it's an arbitrary name ?
that's a type
So am I
So I can name something more descriptive like DailyRoutineEvent ?
sure
And this looks like JSON, is it possible to make this even more modular by allowing me to do the modifications in the inspector or in a SO ?
yeah just make a struct for it and serialize a list of that struct
I was just trying to express some sample data to you, don't read into it being Jsonish
Whatever you want
But then what's the right type for that ?
Yes - i was just expressing the information to you
in reality the information would live in a class or struct in a list
so what's the best type for that
A custom type called Event or DailyRoutineEvent containing a start time and an event name/identifier of some sort
as we have been discussing
super simple example:
public class DailyRoutineEvent {
public string Name;
public float TimeOfDay; // In fractional hours [0, 24) e.g. a value of 6.5 here would mean 6:30AM, and a value of 13 would be 1PM
}```
oh I'm dumb π€¦ββοΈ
and isn't it possible to not write the hours as float but as Military time ? π Because I have to do math if it's not 6:00 or 6:30 π
should probably be a struct, eh?
how would you get a literal of that
would have to separate the minutes or use a string
that's what I did before π
using a string is not particularly safe since it's way more flexible
you could do whatever you want but strings are silly. This float is a much simpler way of expressing that
bordering into too flexble for this kind of thing
Like this, where the 2 firts numbers = minutes, then 2 hours number, then 2 days number
there's no need for this swtich anymore
remember we're discussing replacing it entirely
what happens if you typo a number
what happens if you accidentally add a space
what happens if you accidentally add an invisible character in the code
these are all silent errors
you get bugs with no trace of where it came from or why it happened
a number type gives you a narrower space of possibilities, which removes these string issues
like 0.5 = 30 min, so if I want 6:50AM, you will need to start to do math to know what 50 / 60 is
you would instead have a completely different switch somewhere based on the event name. e.g.
public void perform(DailyRoutineEvent evt) {
switch (evt.Name) {
case: "breakfast":
Debug.Log("You eat a hearty meal!");
}
}```
there is no need to do any math
what is the math for
all you do is if (currentTime.Hours > evt.TimeOfDay)
Like imagine if I want the event to be called at 6:50AM
i think he means to set the value to begin with
I see
instead of 7 AM
then yes it's just 50/60
hence math π
i mean personally that's not too big of an issue, worst case could just stick to .5/.25/.75
You could write one function to parse a string and convert it to the float, sure
that's not a big deal
you can even use TimeSpan.Parse for it
Check the code examples: https://learn.microsoft.com/en-us/dotnet/api/system.timespan.parse?view=net-9.0#system-timespan-parse(system-readonlyspan((system-char))-system-iformatprovider)
so again no math really needed
that's what I showed above (my previous solution) π
the string, if you choose to use it, would just be for getting data into the system. It wouldn't be used during the actual processing.
it is military time but with days in them
it's reversed
how ?
military time is hours before minutes
000700 = 0 days, 7 hours, 0 minutes
and what's 010203?
hey guys, is it possible to change the cinemachine gain value with code. I found the reference here but I canβt access it
2:03 am day 1?
they described it as 2:01 am on day 3 before lol #archived-code-general message
Vector3Int of d,h,m
Anyone?
Why can't you access it? It's public
1 day, 2 hours, 3 minutes (02:03 AM)
oh yeah, my bad
i believe those are structs..
so u need to copy it and assign it back after modifying it
How would I be able to do that
not familiar with the exact property tho.. CinemachineInputAxisController.X maybe?
Ok I will try that
using Unity.Cinemachine;
using UnityEngine;
public class TESTCINEMACHINE : MonoBehaviour
{
public CinemachineInputAxisController myAxisController;
public float desiredGain;
private void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
ChangeAxisGain();
}
}
void ChangeAxisGain()
{
foreach(var controller in myAxisController.Controllers)
{
if(controller.Name == "Look Orbit X")
controller.Input.Gain = desiredGain;
}
}
}``` after some fiddling i found something that works..
just gotta make sure the names are exact
couldn't find any alternative method.. Cinemachine always hard to work with imo when ur hunting up properties and how to modify things.. just trial and error for me
in ur case not sure it'd be "Look X (Pan)" or what.. i'd just test you can probably debug all the different names as well to find the right one
Holy
Thank you so much
foreach(var controller in myAxisController.Controllers)
{
Debug.Log(controller.Name);
}```
yup u can debug the names to find the correct ones for u π
Wow thank you so much for the help
It work now
np π
Ty
ill have to remember to always try finding Controllers first when using cinemachine components
i think this is the 2nd time its played out that way
they probably would have found this sooner had they actually looked at the type they took a cropped screenshot of that contained the field they wanted to modify
Is there a preprocessor directive for determining whether the current build is a developer build in Unity 6?
I can find the DEBUG symbol but DEVELOPMENT_BUILD isn't one that's popping up
https://docs.unity3d.com/6000.0/Documentation/Manual/scripting-symbol-reference.html
DEVELOPMENT_BUILD is the one
a horrifying realization
Yuck
Burn it
Lmao
so this is syntactically fine
it just says x as an int won't match
i hate it so much
What in the Dr. Seuss
Pattern matching with operators is more useful with doing nested matches, less so about direct usage.
it feels wrong
Eg someList is { Count: > 0 } is an alternative to someList != null && someList.Count > 0.
There's not really a point in using someInt is > 0 directly.
unless you want to check a range then you can do someInt is > 0 and < 3
does anyone know how to fix this problem? i tried removing the 2D part at the end of "forcemode" but that doesnt work either
even if you're trying to use the 3d ForceMode, you still have to spell it correctly. although if you are working in 2d then that force mode simply does not exist
ah, that explains it
also make sure your !IDE is configured so you don't make silly spelling mistakes and have access to intellisense which can show you the available members of a type π
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
β’ :question: Other/None
it is also required to receive help here
oh okay, thank you
Okay so I've been making a custom "debug" system, where I draw custom text gizmos with OnDrawGizmos, but, this limits me. I need a way to call a custom function like "OnDrawGizmos" but WITHOUT the need for gizmos to be enabled in the scene view
(OnDrawGizmos needs gizmos to be enabled in order for it to run, I don't want to have to have gizmos enabled in order to run my custom code)
I want my system to run in editor btw, that's why I use OnDrawGizmos
Why donβt you want gizmos enabled
Because it's obnoxious and there's alot of unwanted stuff on screen with gizmos enabled.
your probably gonna need to learn some editor stuff via #βοΈβeditor-extensions
using Handles and other stuff
Alright I'll look into it, thanks!
You can disable gizmos for specific classes in the dropdown
It would definitely be better to look into a custom alternative, maybe even TMPro if you're just using text 
its editor only so probably not tmp
It being editor only doesn't really stop you from using TMP
So here's what I do, whenever something wants to debug a text, I spawn a gameobject and add a 3D TMP text component on it, make the name of the gameobject something to do with instanceID of the gameobject we're trying to debug on, and bam, it works. (theres some other stuff too but whatever)
Problem, where do I tell the game I want to debug, can't be in OnDrawGizmos, because that only runs when gizmos are enabled, but still needs to run in editor. Disabling individual gizmos is kinda annoying tho lol
I looked into editor scripts and found Handles.Label, but again, only works when gizmos are enabled. (as far as I can tell)
at the end of the day its gonna be hard to get around making gizmos without turning them on
If you need custom behaviour across all (or most) of your scripts.. You could make your own MonoBehaviour base class that handles it 
They aren't actual gizmos tho, just spawning gameobjects
they aren't gizmos because you don't want them to be
hmm maybe
what your doing is what gizmos are
Technically, but since they're gameobjects, should be a way to spawn them without gizmos.
which is what your doing with 3d text components yeah
but it's not what Unity's made to handle this solution
if you wanna do editor only in scene debug text "right" all answers are gonna point towards gizmos
I don't think I've done something like that, how would you go about making something like that?
public class BaseBehaviour : MonoBehaviour
{
public virtual void OnDebug()
{
// Call this wherever
}
}```
Or use an interface to add it
public interface IDebuggable
{
public void OnDebug();
}
public class SomeClass : MonoBehaviour, IDebuggable
{
public void OnDebug()
{
}
}```
Okay I know how to do that, yeah, but how could this run every frame in edit mode.
you'd need to have a manager checking if the game is in editor mode and if it is calling that on all those objects
Either ExecuteInEditMode + Update, or a custom editor
Or a neat custom attribute that compacts that
Probably an attribute
How would you do that then...
I've always been curious on how attributes work, so I'd like to learn.
EditorApplication has an update event, I'd create a static class that uses that, plus [InitializeOnLoad] to call it on any method with the attribute
Legit never made a custom attribute, where would the static class go, how do you attach the update event to the custom attribute etc
Really appreciate the help btw lol
[InitializeOnLoad]
public static class EditorUpdater
{
EditorUpdater()
{
EditorApplication.update += Update;
}
protected static void GlobalUpdate()
{
}
}
[AttributeUsage(Method)]
public class UpdateInEditor : Attribute { }```
Written from memory, probably not the most accurate, but you get the idea
I would recommend doing some research into C# attributes, reflection (to get attributes in monoBehaviours, infrequently) and EditorApplication
Alright I think I got this, thanks for the help!
I got as far as the reflection part and I can't get it to work. These are my scripts, and I can't seem to do reflection with a static class.
I might have done reflection wrong I legit have no clue lol
If a class is static, you can't pass this, It's the same as DebugEditorUpdater
Static classes can't have non-static methods, either.
Plus passing this, then using GetType just finds all the methods in that class, not everything using it
And, you definitely do not want to do that in Update
Okay well yeah that's why I can't get it to work with static, other than that tho I don't really know what I'm doing with these, educate me lol
Try FindObjectsByType<MonoBehaviour>(), instead of an object param. I'd try it in EditorApplication.focusChanged, so it refreshes every now and then, or find a way to do it manually, or whenever a component is added, not sure how that works.
Then, for every method with the attribute, add it to a collection, then loop through that collection in Update and call the methods
Hate to keep asking but now what...
I got the IDebuggables in an array (that's what I was supposed to do... right? I'm still supposed to use the interface right?)
Now what do I do in global update?
If you're using an attribute, you don't need an interface
If you're using an attribute, you need to check if the type has a method that uses the attribute, then store a list of methodinfo
I am just about to go to sleep
Well thanks for helping, maybe I can figure it out idk lol
Google is your friend 
Anyone know any good coding bootcamps?
Unity has a !learn site
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
I more so meant ones you could get like certificates for?
And itβs actual class
this is a unity server
not sure what you really intend to get from a unity bootcamp. "certificates" from coding bootcamps have less value than toilet paper.
Honestly, certificates don't mean much in software development world. If you have 10 certificates and another person has 0, but has several sample projects in their portfolio, they have higher chance of being hired than you.
Focus on learning, improving your skills and building something you can actually show off.
Unless you're just collecting certificates as a hobby
Interesting, honestly Iβm just looking to learn how to code so I can do my projects more efficientlyβ¦effectively?
Iβm currently learning c++ whenever I have time
Also dumb question but like, wdym by sample projects?
Just things Iβve coded?
I donβt rlly know how coding resumes work rn havenβt had the time to look into em
Man Iβm just asking
Ideally something close to real life projects you want to be working on professionally. If it's game dev, maybe release a game on google play store or steam.
Gotcha
Even if it's not successful, it is still a great achievement
Yeah thatβd probably be a good way to practice
The bootcamps Iβve found are cool and all but they really just tell you what the stuff means with no real way of studying it or like homework or smthn
Iβll try and figure out some smaller project ideas and build up from there
The other person could literally only have university experience and would be considered over any amount of bootcamps
π€·ββοΈ and I replied. It's really not clear if you're looking for something unity related, and this channel is purely for unity discussions.
If you're looking to do this as a job, I highly doubt you'll get any position without actual professional experience or a degree. The coding bootcamp hype died down 10 years ago. Everyone has sample projects that sound incredibly complex and fancy.
Doing small projects will help you learn and still can be added to your resume, but even people with experience or degrees are struggling.
I've got diplomas and my portfolio has multiple finished small scale games and a mod that managed to get 10mil+ downloads and still no bites from any studios
its brutal out there rn
I guess it depends on where you look for work and what kind of position you're aiming for.
forsure, although my experience includes junior work in a remote, global based context aswell
game-jam style scoped projects are really nice for portfolio though
In relation to anything software, I dont think it depends at all. Dont really wanna go too off topic here but entry level positions at minimum would require a degree. Places just wont hire based on seeing the 5000th linear regression sample project.
I'm talking from my experience. I've released a simple prototype game on play store and worked as a freelancer for a year or so. No degree in CS whatsoever. And I've been hired by a pretty big company in Japan, Osaka.
Even before that, I managed to get a job in mobile app related company as well.
So I really think it depends on the area, what you have to show and how to present yourself.
I imagine in America, especially at major cities it's probably more difficult
Interesting, yea that might be more of a regional thing then. That would be extremely rare in america/canada
When did that happen?
It's in my message.
I might be going crazy I cannot see it
Japan, Osaka.
when
ah fair
still fairly uncommon where I live then but only asking because from what I know since COVID stuff has dramatically changed (not just necessarily due to COVID but as a catalyst to other big reasons)
Japan sounds so nice rn compared to shithole Texas
I've had a lot of people mention anecdotes obtained from before the big wave
Well tbh anywhere else sounds better than doodoo Texas
I imagine with so many big tech companies in there, they wouldn't hire anyone with less that 50+ years of C++ experienceπ
Thatβs all over America from what Iβve heard
I think in most major cities due to the big mixups at major studios and general mass amount of layoffs the pool for applicants is so huge that the experience levels in supply far surpass the expected demand
Honestly I think itβs just rough for everyone atp
In Aus right now you have to be mid (aside from in-studio experience) to even be considered for junior
Except maybe if youβre an engineer or smthn
Hey guys I am going to make a save/load system using json. I was wondering what I should do about gameobjects that I spawn in with a script that need to be saved?
So stuff like bullets or something
Save them the same way. If you want.
I don't get it?
What exactly?
this is a code channel, pls delete your question from here and ask the publisher of that asset.
What's "nunit" and how do I delete this trash from getting auto included? Ever since I upgraded to unity 6 the auto include for system.collections is replaced with "NUnit.Framework;"
Sounds like you're using the unit test template instead of Monobehaviour
my scripts are literally created by "new monobehaviour script" which to be exact creates a class that derives from monobehaviour
and in case it's still ambiguous, monobehaviour is the unity's class that's been there since many years
and in case you still doubt, unity as in game engine that's related to this discord
No need to be rude
check the template script file for the editor
I was just specifying things to avoid unnecessary questions of doubt, not intending to be rude
Why did they suddenly change the default template script wtf
Well if it's including NUnit it sounds like someone messed up
It's not letting me overwrite the script and I recall several years ago it was still possible
nevermind it's just windows being crap as usual
Might need to do it as admin, since Unity installs in Program Files
i need to create a drop down menu in the inspector with the 24 hours of the day (+ the half of it), is there a better way than writting them all one by one ? Maybe there's something in the TimeSpan class to do that ?
This is what I want to display in the drop down list in the inspector :
- 00:00
- 00:30
- 01:00
- 01:30
- 02:00
- ....
- 23:00
- 23:30
Like I want to have that inside a struct that I want to use in a Scriptable Object that will appear in the inspector when I select it
Like I have something like this right now, but I used "TimeSpan" for now but I think it's not the right answer but it's just there to give you an idea of what I'm going for
You can make a propertydrawer for it https://docs.unity3d.com/6000.0/Documentation/ScriptReference/PropertyDrawer.html
I need it to be SO because there will be different daily tasks and time depending on the prison π¬ Though my question is more about a way to generate those 48 hour values instead of typing them by hand π¬
for(int i = 0; i < 24; i++)
{
list.Add($"{i:00}:00";
list.Add($"{i:00}:30";
}
?
Combined with propertydrawer of course
why is there :00 twice ? π€
the first is formatting, the second is actual string content
The first is for string formatting
same as doing i.ToString("00");
https://paste.mod.gg/gqkvcrxmlvez/0
Can someone see why when I slide upwards my speed is dramtically amplified
A tool for sharing your source code with the world!
it should be slowed down due to gravity
@vestal arch @last quarry @steady bobcat Thanks π Isn't there a way to do that with TimeSpan, as in a sense I still need to compare those to TimesSpan from my previous code to check if we're between the start and end of those times to call an event π€ ?
time span has quite good to string formatting options so yes
which is ... ?
Well your actual serialized value would be an int I guess (position in the list)
Remember you can serialize the time as unix ms as a long
you can use DateTimeOffset to convert to and from easily
If anyone says save it as a string i will throw a shoe at you π
So the hour would be the index divided by two. The minute would be 0 if the number is even and otherwise 30
iso8601
π i like unix ms too much
save it in unix ms but as a string
Wait that's kinda complex because in my case there's a shift that needs to happen as IRL secs = IG minutes
im sure you can figure out the maths for going from MS -> S -> M -> H...
Unix MS is more for storing a specific date + time than some amount of time
And its worth noting that DateTime/DateTimeOffset and TimeSpan can all be used together quite easily
Encode it into a PNG, pass that PNG to a texture, give that texture to a shader, and have the shader use the data to drive an oscilliscope graph, then interpret the time from the peaks and valleys of the beam
Hey @steady bobcat sorry to ping just remember you helping me the other day, I got splines working with the road in spline extrude but why do the ends of the road round themselves instead of staying flat? Or maybe it curves I guess? Also was curious if you knew about a good double sided shader or a good asset pack possibly already bringing in this feature?
Its super easy to do yourself with a shader graph:
and there is probably some setting for rounding the ends by some amount?
does anyone know how to fix cursor lock not working unless I click in the game window when a new scene is loaded from a different scene (when the project builds).
I have two scene Title and Sandbox.
When I click on a UI button to load the sandbox scene, the mouse isn't is focus and I need to hit the window's key before it becomes in focus again.
using UnityEngine;
using System.IO;
using UnityEngine.SceneManagement;
namespace Title {
public class TitleMenu : MonoBehaviour {
// public string NewGameString;
public void ConinueGameButton() { }
public void NewGameButton(string NewGameString) {
SceneManager.LoadScene(NewGameString);
}
public void SandboxButton(string SandBoxString) {
// I'm loading the sandbox scene here
// cursor should be locked at the start of the scene
SceneManager.LoadScene(SandBoxString);
}
public void QuitGameButton() {
Application.Quit();
}
}
}
this is attached to a gameObject in the sandBox scene.
using UnityEngine;
using System.Collections;
public class OnStartCursorLocker : MonoBehaviour
{
[SerializeField] private bool lockCursorOnStart = true;
[SerializeField] private CursorLockMode lockMode = CursorLockMode.Locked;
[SerializeField] private bool hideCursor = true;
private void Awake() {
StartCoroutine(InitializeCursor());
}
private IEnumerator InitializeCursor() {
for (int i = 0; i < 3; i++){
yield return new WaitForEndOfFrame();
}
if (lockCursorOnStart) {
ApplyCursorSettings();
}
}
private void OnApplicationFocus(bool hasFocus) {
if (hasFocus) {
StartCoroutine(ReapplyCursorSettings());
}
}
private IEnumerator ReapplyCursorSettings() {
for (int i = 0; i < 3; i++) {
yield return new WaitForEndOfFrame();
}
if (lockCursorOnStart) {
ApplyCursorSettings();
}
}
private void ApplyCursorSettings() {
Cursor.lockState = lockMode;
Cursor.visible = !hideCursor;
// Debug.Log($"Applied cursor: {Cursor.lockState}, Visible: {Cursor.visible}");
}
}
I even went into the script execution order and placed the OnStartCursorLocker at -1 (right before the Cinemachine cod) but it still had no effect.
Oh word thanks brother man! I will try this when home, yes the rounding seems to be setting the width of the road within extrude which is strange but maybe itβs just a half circle or something getting stretched Iβm unsure lol.
Looking at Spline extrude myself i cant make it be flat. When I have done stuff before i've used a line renderer that I synced to the spline myself.
no idea what uses this but may be useful https://docs.unity3d.com/Packages/com.unity.splines@2.8/api/UnityEngine.Splines.ExtrusionShapes.Road.html
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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 a way to get scripting defines to function in the IDE?
is your IDE configured? if so then they should work
It should be as the .csproj is recognized as Assembly-CSharp and not a miscellaneous file
Maybe I'm missing something. Unity didn't try to recompile when I defined a symbol though. Not sure if I'm missing something but it feels like it should
Ah wait no sorry I made an incredibly dumb slip-up
I spent so much time on my custom build profile that I forgot to switch to it lol
Okay THIS is annoying is there a way to turn this off
It's nice that it's smart like that but unfortunately that's not what I want
It's saying the code is unreachable but I don't want it to point that stuff out because of the symbol
Why not put it in an #else?
well it is unreachable in your current profile. you can probably use a pragma to disable that warning inline though
or yea, an else
I suppose that works yeah
Unfortunately that causes this
I suppose it's again doing what it's meant to because it's the defines have been configured
move the endif up a line
Oh crap
Still greys out the code which wont be used which I don't want
Generally speaking I just want a way to mask out code for builds that aren't developer builds
well yeah, that's how conditional compilation works. that code will not be compiled in the current build profile so it is greyed out
It'd be nice if I had intellisense and such while working on it or something that wont be compiled but I can work with that
I'm stuck, I really struggle to make it sense and implement it π
Tried to have that method to do the loop inside an SO but as SO aren't gameobjects on their own that are directly in the hierarchy / world, it can't execute its constructor that would call that method to generate all the 24 hours
show what you tried for the property drawer since that would be how you get the inspector dropdown menu you said you wanted
nowhere here are you doing anything at all with a property drawer. also !code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
better ?
using System;
using System.Collections.Generic;
using Diversity;
using UnityEngine;
[CreateAssetMenu(fileName = "SO_DailyTasks", menuName = "ScriptableObjects/SO_DailyTasks")]
public class SO_DailyTasks : ScriptableObject
{
[SerializeField] private List<DailyTask> task;
[SerializeField] private List<string> time;
public SO_DailyTasks()
{
AddAllHours();
}
private void AddAllHours()
{
for (int i = 0; i < 24; i++) {
time.Add($"{i:00}:00");
time.Add($"{i:00}:30");
}
}
}
[Serializable]
public struct DailyTask
{
private EN_DailyRoutine name;
private TimeSpan startTime;
private TimeSpan endTime;
}
where the drawers at doe
sure, but again, you're not doing anything with a property drawer here so i don't know what you are expecting
I don't know π€·ββοΈ I'm not sure to understand drawers properly
have you done any research about them? or even read the page that was linked to you?
I read the page that was sent to me, but not fully, just discovered now that there were more infos after scrolling π
can I put an SO here ?
alright
however you probably want the property drawer for your DailyTask type instead
oh
Just a tip guys, when should I use public vs [serializefield] private
it's a stylistic choice, choose one and stick with it
in general you shouldn't expose all your fields to every other class when that's unnecessary
yeah the "ideal" would be no public fields unless absolutely necessary and just use public properties to expose things to other objects if they need it
Use private until you have to not use private
Ok cool